Email regex tester: compare patterns and copy code for JS, Python, PHP and Go
There is no single correct email regex. Each common pattern draws the line differently: the HTML5 pattern accepts a@b, a strict pattern rejects legal addresses like o'brien@, and none can tell whether a mailbox exists. Paste addresses to see which patterns accept each one, test your own, and copy your pick in JavaScript, Python, PHP or Go.
Leave out the slashes. Your pattern runs in a separate worker and is stopped after 3 seconds if it hangs.
Copy a pattern
RFC 5322's dot-atom form: no leading, trailing or double dots, a domain with at least one dot. Quoted local parts are left out, as most systems do.
const EMAIL_RE = /^[A-Za-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[A-Za-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/;
export function isEmailShaped(email) {
return email.length <= 254 && EMAIL_RE.test(email);
}Sample result
3 addresses tested, and the patterns disagree on 2 of them.
- Addresses
- 3
- Pass every pattern
- 1
- Fail every pattern
- 0
What this means for you
A pattern only checks format; pick one that fits your form, then check the real addresses.
- Simple, HTML5, RFC 5322 and strict patterns
- Test your own pattern and flags too
- Shows where the patterns disagree
- Code for JavaScript, Python, PHP and Go
- Regex
- RFC 5322
- Code
By SimpleVerifier Team · Last updated · Runs in your browser; nothing you paste is sent to us
How do I test an email regex?
- Paste addresses, one per line, or press Try an example for a set of edge cases.
- Optionally enter your own pattern, without slashes, and any flags. It runs in a separate worker, so a pattern that hangs is stopped after three seconds.
- Press Test addresses. Each row shows a tick or cross per pattern; rows where the patterns disagree are the ones worth reading.
- Pick a pattern and a language under Copy a pattern. The code uses the same source string in every language, with a 254-character length check.
Example
- You enter
- Three addresses:
jane@acme.example,jane..doe@acme.exampleandjane@example. - You get
jane@acme.examplematches all four built-in patterns.jane..doe@acme.examplematches only Simple and HTML5, andjane@exampleonly HTML5, so the patterns disagree on 2 of the 3.- Limits
- Runs in your browser; a custom pattern runs in a separate worker and is stopped after 3 seconds.
What is the regex for email validation?
There are several in common use, and they disagree on edge cases; these are the four worth knowing. Simple, ^[^\s@]+@[^\s@]+\.[^\s@]+$, only asks for something, an @, something, a dot and something. It's fine for a form hint and lets through double dots, leading dots and hyphen-led domains.
HTML5 is the WHATWG definition of a valid email address, the pattern browsers apply to <input type="email">. The specification itself calls it a willful violation of RFC 5322. It allows dots anywhere in the local part and accepts user@localhost and a@b, because intranet hosts don't need a dot.
RFC 5322 dot-atom follows the RFC 5322 rule for unquoted local parts: the same characters, but no leading, trailing or consecutive dots, and a domain with at least one dot. Strict narrows the local part to letters, digits and . _ % + - and requires an alphabetic top-level domain, which rejects legal but rare addresses such as o'brien@example.ie.
How do I validate an email with regex in JavaScript, Python or PHP?
Use the same anchored pattern in each, plus a 254-character length check, as the snippets on this page do. All four patterns avoid lookarounds and backreferences, which Go's RE2 engine doesn't support, so the same source string runs in JavaScript, Python's re, PHP's PCRE and Go. The snippets anchor the whole value: Python uses fullmatch, and PHP adds the D modifier so $ doesn't accept a trailing newline, a common source of bypasses.
Each snippet also checks length. RFC 5321 limits a path to 256 characters including the angle brackets, which leaves 254 for the address. For language-specific guides, see validating email in JavaScript, Python and PHP.
Is regex enough for email validation?
No: regex checks the shape of an address, not whether the domain takes mail or the mailbox exists. A pattern checks shape. jane@gmial.com passes every pattern on this page, and so does the address of someone who left the company last year. Typos, domains with no mail server and mailboxes that no longer exist all look fine to a regex.
For a list you already have, the bulk email syntax checker explains why each address fails rather than just whether it matches, and the email typo corrector fixes common domain misspellings. Telling whether a mailbox exists takes an SMTP check against the receiving server; see syntax check vs SMTP verification.
Which email regex is strictest?
| Address | Simple | HTML5 | RFC 5322 dot-atom | Strict |
|---|---|---|---|---|
jane..doe@example.com | Pass | Pass | Fail | Fail |
a@b | Fail | Pass | Fail | Fail |
o'brien@example.ie | Pass | Pass | Pass | Fail |
x@-example.com | Pass | Fail | Fail | Fail |
jane@gmial.com | Pass | Pass | Pass | Pass |
Who uses this tool, and for what?
- Front-end developers
- Check what a sign-up form will reject before shipping, and avoid blocking real customers with apostrophes or plus tags in their address.
- Back-end developers
- Copy one pattern that behaves the same in the JavaScript client and the Python, PHP or Go server, so client and server never disagree.
- QA engineers
- Paste a list of edge cases and keep the downloaded results as the expected-output table for tests.
- SaaS teams
- Decide how strict signup validation should be, then add a real-time verification API for the typos and dead mailboxes no regex can catch.
What can’t this tool tell you?
- No pattern here accepts quoted local parts or IP-literal domains; real-world mail almost never uses them.
- Internationalised addresses (non-ASCII letters, RFC 6531) are rejected by every pattern except Simple.
- Custom patterns run with JavaScript semantics; Python, PHP and Go differ on some features such as lookbehind.
- A match only means the address is well formed. Typos like gmial.com and closed mailboxes pass.
Common questions
- What is the standard regex for email validation?
- There isn't one standard. The closest to a shared reference is the WHATWG pattern browsers use for input type=email, listed here as HTML5. For most sign-up forms the RFC 5322 dot-atom pattern is a better fit: it rejects double and leading dots and requires a dotted domain.
- How do I validate an email with regex in JavaScript?
- Test the trimmed value against an anchored pattern and check its length:
email.length <= 254 && EMAIL_RE.test(email). Pick a pattern under Copy a pattern and choose JavaScript for a ready function. In a form, input type=email already applies the HTML5 pattern. - What is the regex for email validation in Python?
- Compile the pattern with re.compile and use fullmatch, which anchors both ends:
EMAIL_RE.fullmatch(email) is not None. Avoid re.match with a trailing $, which also accepts a newline at the end. The Python snippet above is ready to copy. - What is a valid email address regex?
- One that accepts what real mail systems accept: letters, digits and characters such as . _ % + - ' in the local part (no leading, trailing or double dots), an @, and a domain of dot-separated labels. The RFC 5322 dot-atom pattern on this page follows those rules.
- Is my custom regex safe to test here?
- Yes. It runs in a separate Web Worker in your browser, so a pattern with catastrophic backtracking is stopped after three seconds instead of freezing the page. Nothing you paste is sent to a server.
Sources
That was one address. Most people have a list.
The free checker does five addresses a minute, one at a time — fine for spot-checking, useless for a CSV of 40,000.
- Upload a CSV up to 100,000 rows
- Valid, risky and invalid exported as separate files
- Repeat checks free for 14 days, no new connections
One plan, cancel anytime, no contract. Sign in with Google and your first 100 email checks are free, no card. The free tools stay free either way.