You are here

public static function Email::validateEmail in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 76
Contains \Drupal\Core\Render\Element\Email.

Class

Email
Provides a form input element for entering an email address.

Namespace

Drupal\Core\Render\Element

Code

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.', array(
      '%mail' => $value,
    )));
  }
}