Skip to content

Instantly share code, notes, and snippets.

@juliyvchirkov
Last active January 15, 2025 21:26
Show Gist options
  • Save juliyvchirkov/30337123712f345fab264516800d6302 to your computer and use it in GitHub Desktop.
Save juliyvchirkov/30337123712f345fab264516800d6302 to your computer and use it in GitHub Desktop.
javascript: strict e-mail address verification
/**
* Provides strict verification of e-mail address
* Includes support for unicode
*
* @param string E-mail address to verify
* @return boolean True if e-mail address is valid, false otherwise
*/
const validEmail = (email) =>
Object.prototype.toString.call(email).slice(8, -1) === String.name &&
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.includes('..') ||
email.startsWith('.') ||
email.includes('.@') ||
email.includes('-.') ||
email.includes('.-'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment