user_validate_name

user_validate_name($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.

File

core/modules/user/user.module, line 267
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();
  }
}
doc_Drupal
2016-10-29 09:53:22
Comments
Leave a Comment

Please login to continue.