Skip to content

Instantly share code, notes, and snippets.

@janziemba
Forked from juanpablocs/valid_email.md
Last active June 27, 2018 17:35
Show Gist options
  • Save janziemba/53d119e06ff4584c6b17bb8fb45acac5 to your computer and use it in GitHub Desktop.
Save janziemba/53d119e06ff4584c6b17bb8fb45acac5 to your computer and use it in GitHub Desktop.
Regex for valid email

regex valid update

const validEmail(str) => !/(\.{2}|-{2}|_{2})/.test(val) && /^[a-z0-9][a-z0-9-_\.]+@[a-z0-9]+([a-z0-9-])?[a-z0-9]\.[a-z]{2,10}(?:\.[a-z]{2,10})?$/.test(val);

validEmail('[email protected]'); //true
validEmail('[email protected]'); //false
validEmail('[email protected]'); //false
validEmail('[email protected]'); //false
validEmail('[email protected]'); //valid
validEmail('[email protected]'); //valid
validEmail('[email protected]'); //valid

more use cases: https://regex101.com/r/2ZKtyk/2/tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment