function user_validate_name in Drupal 9
Same name and namespace in other branches
- 8 core/modules/user/user.module \user_validate_name()
- 4 modules/user.module \user_validate_name()
- 5 modules/user/user.module \user_validate_name()
- 6 modules/user/user.module \user_validate_name()
- 7 modules/user/user.module \user_validate_name()
Verify the syntax of the given name.
Parameters
string $name: The user name to validate.
Return value
string|null A translated violation message if the name is invalid or NULL if the name is valid.
2 calls to user_validate_name()
- SiteConfigureForm::validateForm in core/
lib/ Drupal/ Core/ Installer/ Form/ SiteConfigureForm.php - Form validation handler.
- UserValidationTest::testUsernames in core/
modules/ user/ tests/ src/ Kernel/ UserValidationTest.php - Tests user name validation.
File
- core/
modules/ user/ user.module, line 206 - Enables the user registration and login system.
Code
function user_validate_name($name) {
$definition = BaseFieldDefinition::create('string')
->addConstraint('UserName', []);
$data = \Drupal::typedDataManager()
->create($definition);
$data
->setValue($name);
$violations = $data
->validate();
if (count($violations) > 0) {
return $violations[0]
->getMessage();
}
}