The PHP funtion below checks for the validity of the email address passed to it.
PHP function
function isValidEmail($address)
{
return preg_match("/^[a-z0-9._\-]+[@]([a-z0-9\-]+[.])+([a-z]{2,4})\$/i",
$address);
}
Using the function
if(!isValidEmail($_POST["email_address"]))
echo "Please input a valid email address.";
else
echo "Your email is valid";
1 comments:
The expression you are using would exclude many valid emails. I have to point out you can't truly validate an Email with a regular expression. See http://regexadvice.com/blogs/mash/archive/2004/07/15/314.aspx for more on this point.
Post a Comment