Skip to content

Instantly share code, notes, and snippets.

@juliyvchirkov
Last active March 12, 2021 06:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save juliyvchirkov/30337123712f345fab264516800d6302 to your computer and use it in GitHub Desktop.
javascript: strict e-mail address verification
/**
* Provides strict e-mail address verification
* Includes support for unicode
*
* @param string e-mail address to verify
* @return boolean true if e-mail address is valid, false otherwise
*/
function validEmail (email) {
'use strict'
return typeof email === 'string' &&
email &&
email.length < 256 &&
/^(?:[0-z!#$%&'*+/=?^_`{|}.~-]|[^\u0000-\u007F]){1,64}@(?:(?:[0-z-]|[^\u0000-\u007F]){1,62}\.)+(?:[0-z]|[^\u0000-\u007F]){2,63}$/i.test(email) &&
email.indexOf('..') === -1 &&
email.indexOf('.') !== 0 &&
email.indexOf('.@') === -1 &&
email.indexOf('-.') === -1 &&
email.indexOf('.-') === -1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment