/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/
Never been to CodeSnippets before?
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)
Valid Email Format RegEx (See related posts)
Comments on this post
You need to create an account or log in to post comments to this site.
Related Posts
» Validate email addresses wit... in email regex validate
» extract email addresses in php email regex
» Validate an email address in php email regex
» Simple Email Address Syntax ... in email validation syntax c-sharp
» Subscribe to a RSS feed of y... in apache php mysql find awk email lighttpd ruby rails ssh date perl regex shell textpattern svn osx mac css python google html bash subversion backup script sql javascript dom expressionengine java flash actionscript rubyonrails unix linux applescript cli c ajax image xml terminal file web sed list delphi administration directory
» Grep Rails log file targetin... in apache php mysql find awk email ruby rails time date perl regex shell http osx css python calendar google input html bash windows sql activerecord javascript java actionscript rubyonrails unix linux fixtures database textmate c text XSLT image string location xml swing copy xmlhttprequest array onload tags web url function math json io download parser imagemagick utf8 dos hash convert batch rectangle binary C++ map jpeg delicious series60 rexml camera zoom zope
Snippets (source code soon to be available) developed by Peter Cooper and powered by Ruby On Rails
Validating email addresses is notoriously difficult and should probably never even be attempted with a regular expression. Instead, best practices is to use a library provided by the environment you are using. Perl, Python, Java, Ruby, etc., all have such libraries and they are both faster and more reliable than using a reg-ex. As an added bonus, these have been tested and used in real-world applications and are thus less likely to bite you when you don't expect it.
Now, don't just take my word for it, but check out the little nightmare that is RFC2822 (the rule that govern email formats on the internet) at http://www.faqs.org/rfcs/rfc2822.html, or read advice from sources such as ybiC's "Don't Use Regular Expressions To Parse IP Addresses!" at http://www.perlmonks.org/?node_id=221512
For an interesting example of hard this can be, check out "Mastering Regular Expressions/3e", by Jeffrey Friedl. He has a short example in Chapter 5 on how to match an IP address that ends up a couple of lines long (and I'm still not convinced he gets IPv6 quite right). So that doesn't even cover domain names or what's on the left side of the @.
All in all a very hard problem.