function user_validate_name
Same name in other branches
- 7.x modules/user/user.module \user_validate_name()
- 8.9.x core/modules/user/user.module \user_validate_name()
- 10 core/modules/user/user.module \user_validate_name()
- 11.x core/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 210
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();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.