NYCPHP Meetup

NYPHP.org

[nycphp-talk] Validating Email Addresses

Mark Armendariz nyphp at enobrev.com
Thu Dec 2 16:16:40 EST 2004


Here's a pattern I've been using for a while with success.

/(?P<name>(?:(?P<name_normal>[^\[\]()<>@,;:\\".]+)|"(?P<name_quoted>[^\\"]+|
[\\.]+)*")*(?P<angle><))?(?P<user>(?!\.)(?P<user_normal>\.?[^\[\]()<>@,;:\\"
.
]+)+|"(?P<user_quoted>[^\\"]+|[\\.]+)*")@(?P<domain>(?:(?!-)(?P<sld>[a-zA-Z\
d\-]+)(?<!-)\.)+(?P<tld>[a-zA-Z]{2,})|\[(?P<ip>(?:(?(?<!\[)\.)(?:25[0-5]|2[0
-4]\d|[01]?\d?\d)){4}|(?:(?P<servername>[a-zA-Z\d\-]*[a-zA-Z\d]):(?P<port>\d
{2,5})))\])(?(4)>)/

And here's some examples:
http://dev.enobrev.com/email/

And the code for the example:
http://dev.enobrev.com/email/index.txt

Mark




More information about the talk mailing list