I tried PHP’s built-in function: filter_input()
var_dump(filter_var('john.doe.@gmail.com', FILTER_VALIDATE_EMAIL));
Output:
string(19) “john.doe.@gmail.com”
Then I tried the latest release of Zend Framework (1.11.3):
$validator = new Zend_Validate_EmailAddress();
if ($validator->isValid('john.doe.@gmail.com')) {
echo 'OK';
} else {
foreach ($validator->getMessages() as $message) {
echo "$message\n";
}
}
Output:
‘john.doe.’ can not be matched against dot-atom format
‘john.doe.’ can not be matched against quoted-string format
‘john.doe.’ is no valid local part for email address ‘john.doe.@gmail.com’
Either the built-in function should return FALSE or the Zend method ‘OK’.
My hubmle question is:
Which one is right?
http://framework.zend.com/manual/en/zend.validate.set.html doesn’t really indicate wether they’re being RFC-strict or not, so lets look at the source.
In the source, _validateLocalPart() defines the EBNF they’re matching against:
It looks like they definitely do stay strict to that – so the local part cannot begin or end with a dot.
The pattern above is exactly the same as in the rfc2822 spec: http://www.ietf.org/rfc/rfc2822.txt – and the isValid docblock in Zend/Validate/EmailAddress.php references it as using 2822.
So, if you want to be rfc2822 compliant, Zend_Validate_EmailAddress is doing it right, and likely, the filter_input is doing it out of spec.