Skip to content

Instantly share code, notes, and snippets.

@dmmarmol
Last active December 30, 2017 15:52
Show Gist options
  • 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\ [email protected]',
'Joe.\\[email protected]',
'"Abc@def"@example.com',
'"Fred Bloggs"@example.com',
'customer/[email protected]',
'[email protected]',
'!def!xyz%[email protected]',
'[email protected]',
'Abc\@[email protected]'
];
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