Email Regular expression

Stuck trying to come up with the perfect regular expression for email validation?!?!  Well look no further – here’s one that I’ve found “perfect” to date!  It seems to cover all the clever variants and funny characters that are accepted in email addresses!

Bet you didn’t know the apostrophe and many other “special” characters are actually valid in an email address.  Here’s a quick low-down on what I know is accepted (if you find out any more let me know!):

  • Uppercase and lowercase English letters (a–z, A–Z)
  • Digits 0 to 9
  • Characters # $ % & ' * + - / = ? ^ _ ` { | } ~
  • Character . (dot, period, full stop) provided that it is not the first or last character, and provided also that it does not appear two or more times consecutively (e.g. craig..cartwright@example.com).

So here’s the useful reg expression:

/^[\.\#\$\%\&\’\*\+\-\/\=\?\^\_\`\{\|\}\~0-9A-Za-z]+\@[A-Za-z0-9\-\_\.]+\.[A-Za-z]{2,4}$/

Hope this helps!

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.