Skip to content

Email Regex Tester

A practical pattern for checking that an email address is shaped right, with addresses it accepts and rejects. Edit it and test your own.

JavaScript
269 characters

One case per line; the m flag makes ^ and the end anchor work line by line.

Link optionspattern only

The address bar holds the pattern, flags and replacement, so Copy link shares them. Your test text stays out of it unless you include it (up to 2,000 characters), because it may be private. Nothing is sent to a server.

Matches

6matches

The first is “jane.doe@example.com”, at position 0.

Groups
none
Characters matched
153 of 269
What the pattern meansHover or tap a part to see it in the pattern and what it matched
How this works: Method, 5 sources, Checked against 2 worked examples,

How this works

Method

Your pattern runs in your own browser’s JavaScript engine, in a background worker that is stopped after 1.5 seconds, so a pattern that backtracks catastrophically can’t freeze the page. The explanation comes from our own parser of the ECMAScript pattern grammar, checked against the engine; what each part matched is found by wrapping that part in one more group and running the pattern again. Conversions to other flavours only rewrite the syntax and list what their documentation says works differently.

How it’s tested

2 worked examples for this page are checked by automated tests before every release: given the inputs, the tool must show the expected answer.

Changes

  • First published, with a library of 19 common patterns and their test cases.

How we make toolsReport a mistake

Worked example

Take jane.doe@example.com, the first case in the tester. Reading the pattern left to right, each part takes its share of the text:

  1. ^The start of the text (matches a position, no characters)
  2. [^\s@]+One or more characters other than whitespace or “@” matches jane.doe
  3. @“@” matches @
  4. [^\s@.]+One or more characters other than whitespace, “@” or “.” matches example
  5. (?:\.[^\s@.]+)+A group (not captured), one or more times: matches .com
  6. $The end of the text (matches a position, no characters)

How the email regex works

The pattern splits an address at its one @ sign and checks each side loosely. [^\s@]+ is the local part: one or more characters that are neither whitespace nor another @. That is deliberately generous, because real mailboxes contain dots, plus signs, apostrophes and hyphens that stricter patterns wrongly reject.

After the @, [^\s@.]+ reads the first domain label, and (?:\.[^\s@.]+)+ insists on at least one more label after a dot. Excluding the dot inside each label is what stops example..com or a leading dot from slipping through, and requiring one dot rules out bare hosts such as jane@localhost, which nobody can email from the public internet.

The anchors at both ends make the whole string match, not just a piece of it. Without them, x jane@example.com y would pass because an address appears somewhere inside.

This is the shape check most sign-up forms need: it catches typos like a missing @ or a space, and leaves the real test, sending a confirmation email, to the mail server.

Test cases

Every case runs as an automated test of this page’s pattern, so the table can’t drift from what the pattern really does.

Test cases for the Email address regex
TextResultWhy
jane.doe@example.comPassesthe everyday shape: name, @, domain with a dot
j.smith+newsletter@mail.example.co.ukPassesplus tags and several domain labels are fine
o'brien@example.iePassesan apostrophe is legal before the @
user_name-42@sub.domain.orgPassesunderscores, hyphens and digits
info@xn--bcher-kva.examplePassesa punycode (internationalised) domain
ana@correo.españa.examplePassesnon-ASCII letters in the domain
jane.doe@Failsnothing after the @
@example.comFailsnothing before the @
jane doe@example.comFailsa space in the local part
jane@exampleFailsthe domain has no dot
jane@@example.comFailstwo @ signs
jane@example..comFailsan empty label between two dots
jane@.example.comFailsthe domain starts with a dot

What it doesn’t check

  • A regex can only check the shape of an address; it cannot tell whether the mailbox exists or accepts mail, so always confirm with a verification email.
  • RFC 5322 allows quoted local parts, comments and spaces inside quotes (for example "john smith"@example.com), which this pattern rejects; almost no real provider issues such addresses.
  • The pattern does not enforce the length limits of 64 octets for the local part and 255 for the domain; add a length check in code if you store addresses in fixed-size columns.
  • It accepts any characters a domain may not really contain, such as an underscore in a host name; the browser’s own type="email" field uses a stricter, ASCII-only rule.

The same pattern in other languages

Converted automatically from the JavaScript version; the tester above always runs JavaScript.

The pattern in Python, PCRE, Go, Java and .NET
FlavourPatternNotes
Python^[^\s@]+@[^\s@.]+(?:\.[^\s@.]+)+\ZUse re.fullmatch(), which needs the whole string to match, instead of relying on the end anchor, which in Python also matches before a final newline.
PCRE^[^\s@]+@[^\s@.]+(?:\.[^\s@.]+)+\z
Go^[^\s@]+@[^\s@.]+(?:\.[^\s@.]+)+$
Java^[^\s@]+@[^\s@.]+(?:\.[^\s@.]+)+\z
.NET^[^\s@]+@[^\s@.]+(?:\.[^\s@.]+)+\z

Sources

Frequently Asked Questions

What is the best regex to validate an email address?

For forms, a loose pattern that checks for text, one @ sign and a domain with a dot is the best trade-off. Strict patterns that try to follow RFC 5322 run to thousands of characters and still reject addresses people really use. Send a confirmation email to prove the address works.

Why does my email regex reject addresses with a plus sign?

Many copied patterns only allow letters, digits, dots and underscores before the @. Plus tags such as name+shop@example.com are valid and common, so use a pattern that allows any character except whitespace and the @ sign there.

Does this pattern allow international email addresses?

Yes. It accepts non-ASCII letters on both sides of the @, so addresses on internationalised domains pass. Whether a mail server delivers to them depends on its support for SMTPUTF8, which no regex can test.

Should I use the same regex on the server?

Use the same rule in both places so a form never accepts an address the server then rejects. The browser check is for quick feedback; the server check is the one that protects your data.