Email Validation Regex: Patterns That Work and Their Limits
A regex checks the shape of an email address, nothing more. See a practical pattern, its limits, and what to add so you reject addresses that cannot receive mail.

TL;DR
- An email validation regex checks the shape of an address. It cannot tell you whether the mailbox exists.
- Keep it simple. A strict pattern that follows every rule in the standards rejects real addresses.
- The HTML specification publishes a practical pattern that browsers use for
type="email". - For real accuracy, add a domain check and a mailbox check on top of the regex.
What an email validation regex can and cannot do#
An email validation regex tests whether a string looks like an address: some characters, an @, and a domain. It is quick, runs in the browser and costs nothing. It is the right first filter.
It is the wrong last filter. anna@gmial.com passes every regex, yet it bounces. That kind of typo is one of the most common ways bad data enters a list. A regex can say "this is shaped like an address". It cannot say "this person can receive mail".
A practical email validation regex#
The HTML Living Standard defines a "valid email address" for <input type="email"> and publishes a matching pattern in its input element section. It is a willful simplification of the full rules, chosen to be practical:
/^[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])?)*$/
Read it in two parts.
- Local part (before
@): letters, digits and a set of allowed symbols. - Domain part (after
@): labels of letters, digits and hyphens, separated by dots, each up to 63 characters.
Use it in JavaScript like this:
const emailPattern = /^[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])?)*$/
emailPattern.test('anna@example.com') // true
Why a perfect regex does not exist#
The full address syntax is described in RFC 5322. It allows quoted strings, comments and unusual characters that almost no real mailbox uses. A regex that covers all of it becomes long, hard to read and slow.
It also gets worse over time. Internationalized addresses with non-Latin characters are valid in many systems, and the simple pattern above rejects them. If you serve a global audience, decide up front whether to support them.
So the usual advice is to be lenient. Reject clear junk, accept anything plausible, and let later checks decide.
What a regex misses#
| Problem | Example | Regex result |
|---|---|---|
| Domain typo | anna@gmial.com | Passes |
| Domain that does not exist | anna@no-such-domain-xyz.com | Passes |
| Mailbox that does not exist | nobody@example.com | Passes |
| Disposable address | tmp@throwaway.example | Passes |
| Role address | info@company.com | Passes |
| Catch-all domain | any@catchall.example | Passes |
Each of these looks fine to a regex and fails in the real world.
Layers of email validation#
Think of validation as a stack. Each layer removes a different kind of bad data.
- Syntax: the regex. Fast and local.
- Domain: does the domain exist, and does it have an MX record? An MX record tells the internet which server receives mail for the domain.
- Mailbox: does the server accept this specific address? This needs an SMTP-level check done carefully.
- Risk: is the address disposable, role-based or on a catch-all domain?
An email verifier runs layers two to four for you. You can also call the Tomba API from a sign-up form.
A layered approach in code#
A sensible sign-up flow combines the layers. First, trim the input and run the regex. If it fails, show a message at once. If it passes, send the address to your server and call a verification service. Store the result with the contact, for example valid, invalid, risky or unknown, so later campaigns can filter on it. Accept risky addresses only if your use case allows it, and ask for confirmation by email when stakes are high.
Testing your regex#
Write a small test list before you ship. Include plain addresses, plus signs, subdomains, long top-level domains, uppercase letters and values with spaces. Add negative cases such as a missing @, two @ signs, a trailing dot and an empty local part. Run the list each time you change the pattern, so a fix for one case does not break another.
Where to run the regex#
- In the browser: for instant feedback. Use
type="email"and a pattern. - On the server: always. Client checks can be skipped.
- Before a list import: to drop malformed rows cheaply.
Never rely on the browser alone.
Common mistakes#
- Using a huge "RFC-compliant" pattern copied from a forum and trusting it blindly.
- Rejecting plus signs.
name+tag@gmail.comis valid. - Rejecting new, long top-level domains by assuming they have two or three letters.
- Treating a passing regex as proof the address works.
- Forgetting to trim whitespace first.
Keep the error message helpful#
When the regex rejects an address, tell the user what to fix. "Please check your email address" is better than "Invalid input". Point to the part that looks wrong when you can, such as a missing @.
FAQ#
What is the best regex for email validation?#
For most apps, the pattern from the HTML specification is a sound choice. It is simple and matches what browsers accept.
Can a regex check if an email exists?#
No. It only checks the format. Use a verifier for mailbox checks.
Should I use the regex from RFC 5322?#
Rarely. It accepts forms that real systems do not use, and it is hard to maintain.
Does type="email" replace a regex?#
It gives you a basic browser check. You still need server-side validation.
How do I validate emails in bulk?#
Drop malformed rows with the regex, then run the rest through a bulk verification job.
Go beyond the pattern#
Use Tomba's email verifier to check domains and mailboxes, not only the format.
// start free
See who Tomba finds at any company
Type a company's domain to see its people, their roles and verified work emails, each with the pages it was found on. Free account, no card.
Free plan · No credit card required · GDPR & CCPA
// about the author