Skip to main content
hank-builds.com

Email Address regex

Matches most common email address formats.

/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g

What it matches

A local part of letters, digits and the punctuation . _ % + -, an @, then a domain with at least one dot and a suffix of two or more letters. That covers the shapes people actually type: tagged addresses like first.last+github@example.com, subdomains, and country-code suffixes such as .co.uk.

Railroad diagram

Read left to right. Every path through the diagram is a string the pattern accepts.

[a-zA-Z0-9._%+-] "@" [a-zA-Z0-9.-] \. {2,} [a-zA-Z]

Drag to pan. Ctrl+scroll to zoom.

Breakdown

gFind all matches instead of stopping after the first
[a-zA-Z0-9._%+-]+Match one of: Literal "a"–Literal "z", Literal "A"–Literal "Z", Literal "0"–Literal "9", Literal ".", Literal "_", Literal "%", Literal "+", Literal "-", one or more
@Literal "@"
[a-zA-Z0-9.-]+Match one of: Literal "a"–Literal "z", Literal "A"–Literal "Z", Literal "0"–Literal "9", Literal ".", Literal "-", one or more
\.Literal "."
[a-zA-Z]{2,}Match one of: Literal "a"–Literal "z", Literal "A"–Literal "Z", 2 or more times

Test cases

Matches

  • info@example.com
  • first.last+github@sub.example.co.uk
  • user_name%test@mail-server.org

Does not match

  • plainaddress
  • user@localhost
  • @example.com

Caveats

No regex validates an email address. RFC 5322 permits quoted local parts, comments and bracketed IP literals that this rejects, and it accepts addresses at domains that do not exist. Use it to catch typos before a form submits; use a confirmation email to establish that the address is real.

More common patterns

Test this against your own input in the regex tester, browse the full pattern library, or check the syntax cheat sheet.