PHP函数filter_var('bob@example.com', FILTER_VALIDATE_EMAIL)
是否使用标准RFC 5322验证电子邮件?
答案 0 :(得分:5)
作为filter_var
使用的正则表达式的作者,我可以确认它没有全面使用RFC 5322(具体来说,它不允许评论和折叠空白区域。)
文章VolkerK链接包含更新的验证 - 包括更准确的RFC 5322实现以及RFC 5321的实现(在我看来更合适的标准) - 但filter_var
没有'已更新,以纳入改进。
答案 1 :(得分:2)
implementation code of that filter:
中有评论void php_filter_validate_email(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
{
/*
* The regex below is based on a regex by Michael Rushton.
* However, it is not identical. I changed it to only consider routeable
* addresses as valid. Michael's regex considers a@b a valid address
* which conflicts with section 2.3.5 of RFC 5321 which states that:
*
* Only resolvable, fully-qualified domain names (FQDNs) are permitted
* when domain names are used in SMTP. In other words, names that can
* be resolved to MX RRs or address (i.e., A or AAAA) RRs (as discussed
* in Section 5) are permitted, as are CNAME RRs whose targets can be
* resolved, in turn, to MX or address RRs. Local nicknames or
* unqualified names MUST NOT be used.
*
* This regex does not handle comments and folding whitespace. While
* this is technically valid in an email address, these parts aren't
* actually part of the address itself.
*
* Michael's regex carries this copyright:
*
* Copyright © Michael Rushton 2009-10
* http://squiloople.com/
* Feel free to use and redistribute this code. But please keep this copyright notice.
*
*/
和"原作"来源很可能是:http://squiloople.com/2009/12/20/email-address-validation/
/**
* Validate an email address using RFC 5322
*
...
所以,你有一个索赔和一个修复了所谓错误的人...... ......除此之外我没有任何线索; - )