BrandonKelly.com
VSTS, TFS, CRM, LINQ, Silverlight and a few other things that suit my fancy...

*THE* Email address validation regular expression

January 21, 2008 11:31 by brandon

Most of us use RegEx to validate simple data such as phone numbers of email addresses, but what expression do you choose? 
 
Nothing's quite as good as opening an SMTP outbound connection and starting a session to validate an email address, but this operation is costly for most data entry scenarios, so I've found this RegEx (which interperts RFC 2822 with about 99.99% accuracy) helpful:

[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|gov|mil|biz|info|mobi|name|aero|biz|info|jobs|museum)\b

You'll need to add new TLDs to the second part of this RegEx as they become available (which is very rare).
 
Source: http://www.regular-expressions.info/email.html


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: Development
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed
Comments are closed