gettoolz.app

Email address regex

A local part of letters, digits and . _ % + -, an @, then a domain ending in a dot and a top-level domain of at least two letters. Copy the pattern, with 5 inputs it accepts and 5 it rejects, each checked against it at build time.

Part of developer tools.

Pattern^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$
JavaScript literal/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/

What the email address regex accepts and rejects

Each result below is the output of the pattern itself, run on the input when this page was built — not a claim copied next to it. A wrong verdict stops the build.

Inputs tested against the Email address regex
InputResultWhy
jane.doe@example.comPassesthe everyday shape
first+newsletter@example.co.ukPassesplus-addressing and a two-part TLD
a_b-c%d@mail.example.ioPassesevery allowed symbol in the local part
jane.doe@exampleFailsno top-level domain
@example.comFailsempty local part
jane doe@example.comFailsa space
jane@exa_mple.comFailsunderscore in the domain
josé@example.comFailsnon-ASCII local part, although RFC 6531 allows it

What it wrongly lets through

These inputs match although they are not valid — checked the same way, so this list is as true as the one above.

Inputs the Email address regex wrongly accepts
InputResultWhy
jane..doe@example.comPassesconsecutive dots are not a valid address
jane@-example.comPassesa domain label cannot start with a hyphen

Limits

  • A regex checks the shape of an address, not that it exists: the only proof that a mailbox works is a confirmation email that gets clicked.
  • The full grammar of RFC 5322 (quoted local parts, comments, IP literals) is far larger than any pattern worth maintaining. This one refuses some legal but rare addresses and accepts a few malformed ones, which is the usual trade for a signup form.
  • Internationalised addresses (non-ASCII local parts and domains) are refused. If your users write their address in their own script, validate loosely — something@something — and let the confirmation email decide.

Try it on your own input

Open this pattern in the regex tester with every example above on its own line. The link adds the g and m flags so that ^ and $ hold per line and every line is tested: the highlighted lines are the ones marked as passing here. Paste your own data in place of the examples — it is matched in your browser and never uploaded.

Other common regexes

Or open the regex tester empty and bring your own pattern.