Skip to content

Instantly share code, notes, and snippets.

@artulloss
Last active February 23, 2022 21:46
Show Gist options
  • Save artulloss/c16cce8f7353eac34268a2310d6a9e60 to your computer and use it in GitHub Desktop.
Save artulloss/c16cce8f7353eac34268a2310d6a9e60 to your computer and use it in GitHub Desktop.
Email Regex Javascript
// This is the same checks as the HTML5 email input form field as outlined in the link below.
// Email regex
/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
function isEmail(email) {
// https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
const regex = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
return regex.test(email)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment