简体   繁体   English

用于在php中进行电子邮件验证的filter_var或自定义函数

[英]filter_var or custom function for email validation in php

Which solution is better, using the built in validation filter_var('email', FILTER_VALIDATE_EMAIL) or a custom function? 哪个解决方案更好,使用内置验证filter_var('email', FILTER_VALIDATE_EMAIL)或自定义函数?

Thanks! 谢谢!

Custom validation gives you more control over how far you want to go with this. 通过自定义验证,您可以更好地控制自己想要达到的目标。 What is and is not valid as an e-mail address is more complex than you might think, and most of the time, it is better to be too lax with this than too strict. 作为电子邮件地址的有效性和无效性比您想象的要复杂得多,而且大多数情况下,对此过于宽松比过于严格更好。 After all, a syntactically valid e-mail address doesn't guarantee that the account actually exists, let alone that it's being actively used. 毕竟,语法上有效的电子邮件地址并不能保证帐户实际存在,更不用说它正在被积极使用。 Something like, it must contain one @, at least one dot after the @, at least one character before the @, and none of the illegal characters, is probably good enough in most cases. 有些东西,它必须包含一个@,@之后至少有一个点,@之前至少有一个字符,而且在大多数情况下都不是非法字符。

Filter var for email remove all characters, except letters , digits and !#$%&'*+-/=?^_`{|}~@.[] . 电子邮件的过滤器var删除所有字符,除了字母数字!#$%&'*+-/=?^_`{|}~@.[] Now it is up to your whether you want to go with this filtration or create a custom solution. 现在,您是否想要使用此过滤或创建自定义解决方案取决于您。

And here is an excellent article on that: 这是一篇很好的文章:

Input Validation: Using filter_var() Over Regular Expressions 输入验证:使用filter_var()超过正则表达式

对于大多数应用程序,PHP的filter_var可能会令人满意,但如果您想比较性能和有效性,请查看此站点http://www.linuxjournal.com/article/9585以了解RFC 2822合规性的含义。

You are welcome to use my free PHP function is_email() to validate addresses. 欢迎您使用我的免费PHP函数is_email()来验证地址。 It's available here . 它可以在这里找到

It will ensure that an address is fully RFC 5321 compliant. 它将确保地址完全符合RFC 5321。 It can optionally also check whether the domain actually exists. 它还可以选择检查域是否实际存在。

You shouldn't rely on a validator to tell you whether a user's email address actually exists: some ISPs give out non-compliant addresses to their users, particularly in countries which don't use the Latin alphabet. 您不应该依赖验证器来告诉您用户的电子邮件地址是否确实存在:某些ISP会向其用户提供不合规的地址,特别是在不使用拉丁字母的国家/地区。 More in my essay about email validation here: http://isemail.info/about . 更多关于电子邮件验证的文章: http//isemail.info/about

I found this while Googling, Hope this explains you better 我在谷歌搜索时找到了这个,希望这能更好地解释你

http://www.addedbytes.com/code/email-address-validation/ http://www.addedbytes.com/code/email-address-validation/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM