Validate an email address

Submitted by editor on Fri, 01/15/2016 - 17:04
Question

Verifies the syntax of the given email address

D7 & D8
if(valid_email_address($mail)){
​//Email is valid
}

 

D8 & D9
if(\Drupal::service('email.validator')->isValid($mail)){
//Email is valid
}

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.