function user_validate_name

Same name in other branches
  1. 9 core/modules/user/user.module \user_validate_name()
  2. 8.9.x core/modules/user/user.module \user_validate_name()
  3. 10 core/modules/user/user.module \user_validate_name()
  4. 11.x core/modules/user/user.module \user_validate_name()

Verify the syntax of the given name.

3 calls to user_validate_name()
install_configure_form_validate in includes/install.core.inc
Form validation handler for install_configure_form().
UserValidationTestCase::testUsernames in modules/user/user.test
user_account_form_validate in modules/user/user.module
Form validation handler for user_account_form().

File

modules/user/user.module, line 631

Code

function user_validate_name($name) {
    if (!$name) {
        return t('You must enter a username.');
    }
    if (substr($name, 0, 1) == ' ') {
        return t('The username cannot begin with a space.');
    }
    if (substr($name, -1) == ' ') {
        return t('The username cannot end with a space.');
    }
    if (strpos($name, '  ') !== FALSE) {
        return t('The username cannot contain multiple spaces in a row.');
    }
    if (preg_match('/[^\\x{80}-\\x{F7} a-z0-9@+_.\'-]/i', $name)) {
        return t('The username contains an illegal character.');
    }
    if (preg_match('/[\\x{80}-\\x{A0}' . '\\x{AD}' . '\\x{2000}-\\x{200F}' . '\\x{2028}-\\x{202F}' . '\\x{205F}-\\x{206F}' . '\\x{FEFF}' . '\\x{FF01}-\\x{FF60}' . '\\x{FFF9}-\\x{FFFD}' . '\\x{0}-\\x{1F}]/u', $name)) {
        return t('The username contains an illegal character.');
    }
    if (drupal_strlen($name) > USERNAME_MAX_LENGTH) {
        return t('The username %name is too long: it must be %max characters or less.', array(
            '%name' => $name,
            '%max' => USERNAME_MAX_LENGTH,
        ));
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.