开发者

How can I verify an email address in PHP? [duplicate]

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

Possible Duplicate:

Is there a PHP libr开发者_如何学Goary for email address validation?

How can I verify an email address in PHP?


If you want to check if an email address exists, check out checkdnsrr:

if (checkdnsrr('you@user.com', 'MX')) {
    echo ':)';
}
else {
   echo ':(';
}

If you want to check if a string is an email address, there are literally millions of regulars expressions out there. There's a native function in php, filter_input that does it, thought I've personally never used it.


filter_var($input, FILTER_VALIDATE_EMAIL)


function isemail($email) {
    return strlen($email) > 6 && preg_match("/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/", $email);
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜