开发者

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

开发者 https://www.devze.com 2023-03-01 16:59 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Is there a PHP libr开发者_如何学Goary for email address validation?
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

精彩评论

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