Results 1 to 1 of 1

Thread: E-mail address validation/finding using regular expressions

  1. #1

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Cool E-mail address validation/finding using regular expressions

    D​ue to the enormous volume of e-mail validati​on 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!\#\$&#37;&'*+\-\/=?^_`{|}~]+|""([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 valida​ting 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 sup​port comments in e-mail addresses. "Yes\ this\ e-mail\ address\ is\ valid".and(this is a comment)@a If you'd like to supp​ort 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
  •  



Click Here to Expand Forum to Full Width