Skip to content

Instantly share code, notes, and snippets.

@linkdesu

linkdesu/isEmail.js

Created Jul 24, 2018
Embed
What would you like to do?
Email Validation Regex
/**
* Follow the description from wiki https://en.wikipedia.org/wiki/Email_address
*
* Valid test address:
*
simple@example.com
very.common@example.com
disposable.style.email.with+symbol@example.com
other.email-with-hyphen@example.com
fully-qualified-domain@example.com
user.name+tag+sorting@example.com
x@example.com
"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com
example-indeed@strange-example.com
admin@mailserver1
#!$%&'*+-/=?^_`{}|~@example.org
"()<>[]:,;@\\\"!#$%&'-/=?^_`{}| ~.a"@example.org
example@s.example
user@[2001:DB8::1]
" "@example.org
*
* Invalid test address:
*
Abc.example.com
A@b@c@example.com
a"b(c)d,e:f;g<h>i[j\k]l@example.com
just"not"right@example.com
this is"not\allowed@example.com
this\ still\"not\\allowed@example.com
*
* Invalid address can not handle:
*
1234567890123456789012345678901234567890123456789012345678901234+x@example.com
john..doe@example.com
john.doe@example..com
*
**/
export function isEmail (email) {
return /^(?:[\w\.\!\#\$\%\&\'\*\+\-\/\=\?\^_`\{\|\}\~]+|\".+\")@(?:[\w\-\.]+|\[[\da-fA-F\:]+\])$/.test(toString(email).toLowerCase())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment