function user_validate_name in Zircon Profile 8
Same name and namespace in other branches
- 8.0 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/ src/ Tests/ UserValidationTest.php - Tests user name validation.
File
- core/
modules/ user/ user.module, line 265 - Enables the user registration and login system.
Code
function user_validate_name($name) {
$definition = BaseFieldDefinition::create('string')
->addConstraint('UserName', array());
$data = \Drupal::typedDataManager()
->create($definition);
$data
->setValue($name);
$violations = $data
->validate();
if (count($violations) > 0) {
return $violations[0]
->getMessage();
}
}