-
Mar 21st, 2012, 11:24 AM
#1
Thread Starter
Stack Overflow moderator
E-mail address validation/finding using regular expressions
Due to the enormous volume of e-mail validation methods that are wrong and frustrating to many people who have periods or plus signs in their e-mail addresses, here is the one e-mail regex to rule them all, as a VB.NET string:
Code:
"((([a-zA-Z0-9!\#\$%&'*+\-\/=?^_`{|}~]+|""([a-zA-Z0-9!\#\$%&'*+\-\/=?^_`{|}~(),:;<>@\[\]\.]|\\[ \\""])*"")\.)*([a-zA-Z0-9!\#\$%&'*+\-\/=?^_`{|}~]+|""([a-zA-Z0-9!\#\$%&'*+\-\/=?^_`{|}~(),:;<>@\[\]\.]|\\[ \\""])*""))@((([a-zA-Z0-9]([a-zA-Z0-9]*(\-[a-zA-Z0-9]*)*)?\.)*[a-zA-Z]+|\[((0?\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])\.){3}(0?\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])\]|\[[Ii][Pp][vV]6(:[0-9a-fA-F]{0,4}){6}\]))"
Remember to prefix with ^ and postfix with $ when validating an e-mail address, too. Also, if you have a bug (unlikely, because I followed the rules to the letter ) then please put it here: https://github.com/minitech/EmailRegex
Finally, an important note: this regular expression does not support comments in e-mail addresses. "Yes\ this\ e-mail\ address\ is\ valid".and(this is a comment)@a If you'd like to support comments, remove all parenthesized substrings that are not also within quotes before beginning. Regular expression for that coming soon.
Last edited by minitech; Mar 21st, 2012 at 11:26 AM.
Reason: Killed most inline text ads.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|