Php script that test e-mail address [duplicate]
Possible Duplicate:
Is there a php library for email address validation?
How I can write php script that test e-mail address is input correctly and verify that the input begins with a series of character followed by t开发者_运维技巧he @
character, another series of character and a final series of characters.
The filter_var()
function, using the FILTER_VALIDATE_EMAIL
filter, should do exactly what you want -- no need to re-invent the wheel ;-)
Use the PHP function filter_var()
with the FILTER_VALIDATE_EMAIL
flag to validate the email address:
$emailValid = filter_var($email, FILTER_VALIDATE_EMAIL);
if($emailValid) {
echo "Email is valid";
} else {
echo "Email is INVALID";
}
I mostly use filter_var
for this, but a fellow github'r notified me that this function is flawed.
He recommended to use the rather more complex validator at http://www.dominicsayers.com/isemail/.
Good luck!
if(preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$email){
$inputcorrectly = true; // Or whatever
}
精彩评论