I am Hack Sparrow
Captain of the Internets.

Email validation Regex in PHP

How do you validate an email using Regular Expression in PHP?

Here is a good regex in PHP which will help you validate a vast number of possible emails, also it is case-insensitive. Useful for checking if an input is a valid email or not.


Below is an example in PHP which validates the value of the variable $email using the above regular expression. For the given example, as you might have guessed already, you will get 'Valid email!'. Play around with different values for $email to see how it works.

$email = 'someone@something.com';
$re = '/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i';
if (preg_match($re, $email)) { echo 'Valid email!'; }
else { echo 'Not an email!'; }

Because of the nature of the standard email format specification, the above regex may fail for some emails, but will catch most of the common emails that common people use. To know more about valid but strange looking emails, follow the link titled "Email address specification - RFC 2822" under the references section.


  1. Email address specification - RFC 2822
  2. PHP preg_match
  3. PHP PCRE Regular Expression

Make a Comment