Validate an email with PHP and Regex

Works with preg_match and preg_match_all which use the PCRE Library.

 

$email = 'editor@devtutorials4u.co.uk'

if (!preg_match('^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$^', $email)) {

echo 'The email address you entered was invalid.';

}


Categorized in: