PHP 内置函数来确定电子邮件是否有效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7115562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP built in function to determine if email is valid
提问by Ralph M. Rivera
Possible Duplicate:
How to validate an Email in PHP?
可能重复:
如何在 PHP 中验证电子邮件?
Does PHP have a built in function for determining if an email address is formatted properly. I know it can't go out and check if the email is actually active; I'm talking about just confirming that an email address is structurally correct.
PHP 是否具有用于确定电子邮件地址格式是否正确的内置函数。我知道它不能出去检查电子邮件是否真的有效;我说的是确认电子邮件地址在结构上是正确的。
回答by Decent Dabbler
filter_var
can do this:
filter_var
可以这样做:
$result = filter_var( '[email protected]', FILTER_VALIDATE_EMAIL );
It returns false
when it failed validation, and returns the e-mail address otherwise.
它false
在验证失败时返回,否则返回电子邮件地址。