Hello,
on 10/23/2005 07:21 PM Robin Vickery said the following:
Checking MX records is not reliable at all.
I agree that it is less useful today, but it still help catches many
domain name typos.
... would it not make sense for there to be a BUILT-IN PHP function of
a TRUE email syntactic validation?
I don't see that being much better than passing a good regular
expression to preg_match.
1. Technically you can't write a regular expression that matches
*all* valid email addresses as part of the address specification is
recursive.
ccontent = ctext / quoted-pair / comment
comment = "(" *([FWS] ccontent) [FWS] ")"
Admittedly 99.99% of people don't even know you *can* comment email
addresses so it's not a huge problem...
If I am not mistaken, PCRE supports recursive regular expressions.
Anyway, the way I got the RFC that is not quite the form of an address
but the way it may be presented in message header. Meaning, you can add
comments in To: or other e-mail header but in reality the comments are
not part of the address.
2. Very few people seem to be capable of recognising a *good* regular
expression, let alone writing one. It seems clear that validating an
address is a task that many people want to do, but few can do
properly. I'd say that's a good reason for making it a built-in
function.
Yes. What I meant is that just copying a good enough regular expression
would be sufficient to use it. There is no need to understand it.
For many years I use this regular expression in popular email validation
and forms generation and validation classes.
Rather than accepting only valid characters, it rejects all invalid
characters as specified in the RFC.
^([-!#$%&'*+./0-9=?A-Z^_`a-z{|}~])+@([-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,6}$
I'm sorry, but this regular expression rejects many perfectly valid
ASCII characters. It seems to take into account only dot-atoms, not
quoted-strings. It also rejects valid addresses using domain-literals.
You are right of course. What I wrote is not what I meant. I fixed the
sentence later but I did not realize that the message had already been sent.
What I meant is that despite I use that regular expression for many
years without complaints, it could be improved to reject only invalid
characters, but of course that is not what that expression does.
--
Regards,
Manuel Lemos
PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/
Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php