Skip to content

Instantly share code, notes, and snippets.

@nkcmr
Created March 16, 2015 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkcmr/0ff9713f7ff1851be991 to your computer and use it in GitHub Desktop.
Save nkcmr/0ff9713f7ff1851be991 to your computer and use it in GitHub Desktop.
best working email regex for javascript [updated]
/**
* i say updated because previously, the regex wouldn't
* like if you entered, 'mikey@rocks.email', which with
* recently added TLDs is a perfectly valid email address.
* So i looked up the maximum length for a TLD (which is
* 63 characters), and put it in here. Now it works pretty well.
* It even acceptes those GMail aliases (mikey+facebook@rocks.email)
*/
var EMAIL_REGEX = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.({2,63})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment