Email regex

^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
  • ^ : Start of the string.
  • [a-zA-Z0-9._%+-]+ : Match one or more alphanumeric characters, dots, underscores, percent signs, plus signs, or hyphens.
  • @ : Match the at symbol (@).
  • [a-zA-Z0-9.-]+ : Match one or more alphanumeric characters, dots, or hyphens.
  • \. : Match a dot.
  • [a-zA-Z]{2,} : Match two or more alphabetical characters.
  • $ : End of the string.

Or use this one if you need to cover emails like these: name@site.com and name@subdomain.site.com.

^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(\.[a-zA-Z]{2,})?$

Angular Email REGEXP

const EMAIL_REGEXP = /^(?=.{1,254}$)(?=.{1,64}@)[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[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])?)*$/;

Leave a Comment