Skip to content

Instantly share code, notes, and snippets.

@dmmarmol
Last active December 30, 2017 15:52
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 dmmarmol/d11e81107d2fcfac19fad5991c9025bb to your computer and use it in GitHub Desktop.
Save dmmarmol/d11e81107d2fcfac19fad5991c9025bb to your computer and use it in GitHub Desktop.
Email RegEx validation
/**
* Usign ES6/Babel
* Demo: http://jsbin.com/tonatohuyi/
*/
function isEmail(value) {
var pattern = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)/;
return pattern.test(value);
}
const emails = [
'Fred\ Bloggs@example.com',
'Joe.\\Blow@example.com',
'"Abc@def"@example.com',
'"Fred Bloggs"@example.com',
'customer/department=shipping@example.com',
'$A12345@example.com',
'!def!xyz%abc@example.com',
'_somename@example.com',
'Abc\@def@example.com'
];
emails.forEach(email => console.log(email, isEmail(email)) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment