Username.php 901 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once 'HTML/QuickForm/Rule.php';
  4. /**
  5. * QuickForm rule to check if a username is of the correct format
  6. */
  7. class HTML_QuickForm_Rule_Username extends HTML_QuickForm_Rule
  8. {
  9. /**
  10. * Function to check if a username is of the correct format
  11. *
  12. * @param string $username Wanted username
  13. * @param array $options
  14. *
  15. * @return boolean True if username is of the correct format
  16. * @author Modified by Ivan Tcholakov, 15-SEP-2009.
  17. * @see HTML_QuickForm_Rule
  18. * The validation rule is served by the UserManager class as of this moment.
  19. */
  20. public function validate($username, $options)
  21. {
  22. if (api_get_setting('login_is_email') == 'true') {
  23. return api_valid_email($username);
  24. } else {
  25. return UserManager::is_username_valid($username);
  26. }
  27. }
  28. }