Skip to content

Instantly share code, notes, and snippets.

@oharsta
Created June 5, 2024 13:23
Show Gist options
  • Save oharsta/9095782782e4e184b24c47d86a20a39d to your computer and use it in GitHub Desktop.
Save oharsta/9095782782e4e184b24c47d86a20a39d to your computer and use it in GitHub Desktop.
JS mail regular expression
const mailRegExp = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.?[a-zA-Z]*$/;
mailRegExp.test("a@a")
// true
mailRegExp.test("a!@a")
// false
mailRegExp.test("a!@a/x")
// false
mailRegExp.test("a_-a@a.x")
// true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment