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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:02:33  来源:igfitidea点击:

PHP built in function to determine if email is valid

php

提问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_varcan do this:

filter_var可以这样做:

$result = filter_var( '[email protected]', FILTER_VALIDATE_EMAIL );

It returns falsewhen it failed validation, and returns the e-mail address otherwise.

false在验证失败时返回,否则返回电子邮件地址。