You are here

function mailchimp_validate_email in Mailchimp 8

Same name and namespace in other branches
  1. 7.5 mailchimp.module \mailchimp_validate_email()
  2. 7.4 mailchimp.module \mailchimp_validate_email()
  3. 2.x mailchimp.module \mailchimp_validate_email()

Wrapper for email validation function in core.

Necessary so email validation function can be added to forms as a value in the #element_validate array.

See also

\Egulias\EmailValidator\EmailValidator::isValid()

1 string reference to 'mailchimp_validate_email'
mailchimp_insert_drupal_form_tag in ./mailchimp.module
Convert Mailchimp form elements to Drupal Form API.

File

./mailchimp.module, line 1456
Mailchimp module.

Code

function mailchimp_validate_email($mail, FormStateInterface $form_state) {
  if (!\Drupal::service('email.validator')
    ->isValid($mail['#value'])) {
    $form_state
      ->setError($mail, t('The email address %mail is not valid.', [
      '%mail' => $mail['#value'],
    ]));
    return FALSE;
  }
  return TRUE;
}