Validate an email address using regular expressions

Validate an email address using regular expressions
Description

If you want a PHP script to verify an email address then use this quick and simple PHP regular expression for email validation. This is also case-insensitive, so it will treat all characters as lower case. It is a really easy way to check the syntax and format of an email address.
The code





$email = "someone@example.com";



if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {

echo "Valid email address.";

}

else {

echo "Invalid email address.";

}



?>

Posted in |