开发者

Php script that test e-mail address [duplicate]

This question already has answers here: Closed 11 years ago.

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
}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜