function Email::validateEmail
Same name in other branches
- 9 core/lib/Drupal/Core/Render/Element/Email.php \Drupal\Core\Render\Element\Email::validateEmail()
- 8.9.x core/lib/Drupal/Core/Render/Element/Email.php \Drupal\Core\Render\Element\Email::validateEmail()
- 11.x core/lib/Drupal/Core/Render/Element/Email.php \Drupal\Core\Render\Element\Email::validateEmail()
Form element validation handler for #type 'email'.
Note that #maxlength and #required is validated by _form_validate() already.
File
-
core/
lib/ Drupal/ Core/ Render/ Element/ Email.php, line 74
Class
- Provides a form input element for entering an email address.
Namespace
Drupal\Core\Render\ElementCode
public static function validateEmail(&$element, FormStateInterface $form_state, &$complete_form) {
$value = trim($element['#value']);
$form_state->setValueForElement($element, $value);
if ($value !== '' && !\Drupal::service('email.validator')->isValid($value)) {
$form_state->setError($element, t('The email address %mail is not valid. Use the format user@example.com.', [
'%mail' => $value,
]));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.