PHP - Simple Validate E-Mail function.

line Tags: ,

I found this by accident, but thought it was useful to take a note as my regular expression knowledge is basic to say the least…


function ValidateEmail($e,$v=-1) {
global $verbose;
/*
Return codes:
0: appears to be a valid email
1: didn't match pattern of a valid email
*/
if ($v==-1) { $v=$verbose; }
if (!preg_match("/^[a-z0-9.+-_]+@([a-z0-9-]+(.[a-z0-9-]+)+)$/i”, $e, $grab)) {
return 1;
}
return 0;
}

Usage is simple….


if(!(empty($_POST['email']))){
$email = ValidateEmail($_POST['email'],$v=-1);
}
// check E-Mail Syntax
if ($email == 1) {
echo “Incorrect Email Address Submitted.
“;
}

Thanks Shane Marriott :)

nick

 

Got something to say?

 

Some other things that might interest you...

---