NYCPHP Meetup

NYPHP.org

[nycphp-talk] Validating Email Addresses

James B. Wetterau Jr. james at surgam.net
Thu Dec 2 13:21:25 EST 2004


Dan Cech says:
 > Daniel Convissor wrote:
 > > Folks:
 > >
 > > On Thu, Dec 02, 2004 at 11:19:23AM -0500, James B. Wetterau Jr. wrote:
 > >
 > >>http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html
 > >
 > >
 > > I feel that regex is way overblown.  Here's my ereg pattern:
 > >
 > > '^[a-z0-9_.=+-]+@([a-z0-9-]+\.)+([a-z]{2,6})$'
...

I feel that that regex is way underblown.

It misses many valid email addresses.  It's perfectly legitimate to
have characters other than [a-z0-9_.=+-] in the local part of the
address.

Here's a handy guide:

http://www.remote.org/jochen/mail/info/chars.html

Note that particularly the equals sign "=" can be used.

All the characters listed as "MAYBE" are legitimate in the local part
of an email address according to the RFC's.  Thus, though this author
puts them in the "maybe" category for creating a new email address, if
you are working with other peoples' email addresses you might want to
be prepared to encounter them.

...
 > The problem with that is that it will reject emails of the form:
 >
 > Joe Bloggs <joe at example.com>
 >
 > or variants thereof.

And that, indeed, is another problem.





More information about the talk mailing list