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