Guide5 min read

Email regex: why validation regex isn't enough

A practical email validation regex, what each part does, the RFC rules it skips on purpose, and the checks a regex can't do: deliverability, burners and typos.

AntiBurnerUpdated

Short answer

Use a regex to catch typing mistakes, not to decide whether an address is real. A good email regex accepts every address providers actually hand out (letters, digits, dots, + and a few symbols before the @, normal domain labels and a real-looking top-level domain) and rejects obvious errors. Everything else, whether the domain receives mail, whether it's a disposable inbox, whether it's a typo of gmail.com, needs DNS and data. Test patterns with the email regex tester.

On this page
  1. A practical email regex
  2. What the standards allow, and why not to accept it all
  3. What about type="email"?
  4. What no regex can tell you
  5. A validation pipeline that works
  6. Questions

Searching for an email validation regex turns up hundreds of patterns, from .+@.+ to a famous 6,000-character monster that tries to implement the whole RFC. Most of them are either too loose to catch anything or too strict and reject real customers, usually people with a + or an apostrophe in their address or a new top-level domain.

This guide gives one practical pattern, explains it part by part, shows what the standards technically allow and why you shouldn't accept all of it, and then covers the part regex can't do at all.

A practical email regex

This pattern (case-insensitive) is the recommended one in the tester. It doesn't need lookbehind, so it works in JavaScript, Python, PHP, Java, Go's RE2 and most other engines:

email-regex.js
const EMAIL = /^[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+(?:[a-z]{2,63}|xn--[a-z0-9-]{1,59})$/i;

Read it in three pieces:

  • The local part, before the @: one or more runs of letters, digits and the symbols RFC 5322 allows (such as +, ', !, #, = and -), joined by single dots. That's the "dot-atom" form from RFC 5322. It accepts ana.lima+promo and o'brien, and rejects a leading dot, a trailing dot and two dots in a row.
  • The domain labels: each label is 1 to 63 letters, digits or hyphens, can't start or end with a hyphen, and is followed by a dot. That's the LDH (letters, digits, hyphen) rule DNS host names follow.
  • The top-level domain: 2 to 63 letters, or an internationalized domain in its ASCII xn-- form. This rejects ana@localhost and ana@example.c, which a sign-up form never needs.

Check the length outside the pattern, where it's readable: at most 64 characters before the @, at most 254 for the whole address. And trim spaces before validating, because people paste addresses with a trailing space far more often than they type invalid ones.

What the standards allow, and why not to accept it all

RFC 5322, which defines the format of email messages, allows much more than any provider hands out. A quoted local part can contain spaces and most punctuation: "ana lima"@example.com is technically valid. The older syntax allowed comments in parentheses. Domains can be IP address literals like user@[192.0.2.1]. And SMTP (RFC 5321) adds its own limits on top.

A regex that accepts all of that is enormous, impossible to review, and accepts addresses that mailbox providers don't create and many mail systems handle badly. Accepting them buys you nothing: the people with those addresses, if any exist, have another one. Rejecting the strange corners on purpose is the practical choice, as long as you never reject the common characters real addresses use.

Common mistakes in email regexes
Pattern mistakeWho it rejects
No + in the local partEveryone who tags addresses, a habit of many careful Gmail and Outlook users
No ' or other symbolsPeople named O'Brien, D'Angelo…
TLD limited to 2–4 lettersAddresses on .photography, .technology and hundreds of other long TLDs
Uppercase not allowedAnyone whose phone capitalizes the first letter
One dot only in the domainmail.example.co.uk and every subdomain address

What about type="email"?

Browsers validate <input type="email"> with a pattern from the HTML standard. It's a reasonable first check for the client side: the local part allows the same symbols, and domain labels follow the LDH rule. It's deliberately loose in two places, though. It allows dots anywhere in the local part (ana..lima@ passes) and doesn't require a dot in the domain, so ana@localhost passes. You can compare it with the recommended pattern in the tester.

Client-side validation is for the user's convenience. Always validate again on the server, because anything sent to your API can skip the browser entirely.

What no regex can tell you

Here are three addresses that every pattern in this article accepts:

  • ana@no-such-domain-4821.com: perfectly formed, but the domain doesn't exist. Your verification email bounces.
  • jane@gmial.com: a typo of gmail.com. The domain may even exist, but Jane will never see your email.
  • x91f@mailinator.com: a disposable inbox anyone can read. The verification link gets clicked and the account is abandoned, or used for another free trial.

Format is the only thing a regex can see. Whether an address works depends on facts that live elsewhere:

  • Does the domain receive mail? A DNS lookup of its MX records answers it: no records, a null MX or a nonexistent domain means no. Try it with the MX lookup.
  • Is it a throwaway? That needs a current list of disposable domains, and for new domains, a comparison of their mail servers with the ones burner services share. How to check if an email address is disposable covers it step by step.
  • Is it a typo? Compare the domain with common providers and suggest the closest one when it's one or two characters away.
  • Does the mailbox exist? Only the mail server knows, and many don't say. Sending a verification email is the one reliable test.

A validation pipeline that works

  1. Trim and check the format with a practical regex and the length limits. Show a friendly message right away.
  2. Check the domain on the server: does it receive mail, is it disposable, is it a typo of a common provider. Offer the correction for typos ("Did you mean jane@gmail.com?") instead of rejecting.
  3. Normalize the address for duplicate checks, so ana.lima+2@gmail.com is recognized as analima@gmail.com. See Gmail aliases and trial abuse.
  4. Send a verification email when the address matters, such as before a free trial or anything that costs you money.

Steps 2 and 3 are one API call with AntiBurner: it checks syntax with the same rules as the recommended pattern, then answers whether the domain is disposable or undeliverable, suggests a correction in did_you_mean for typos, and returns the normalized_email. The quickstart shows the request; the disposable email checker shows the answer for any address.

Questions

What is the best regex to validate an email address?

A practical one: dot-separated runs of letters, digits and symbols like + and ' before the @, LDH domain labels and a top-level domain of at least two letters, case-insensitive. Check the length separately and verify the domain with DNS.

Why does my email regex reject valid addresses?

Usually because it leaves out + or apostrophes, limits the top-level domain to a few letters, or doesn't allow subdomains. Test it against real-world cases in the email regex tester.

Can a regex check if an email address exists?

No. A regex sees only the format. Whether the domain receives mail needs a DNS lookup, and whether the mailbox exists can only be confirmed by sending an email to it.

Should I validate email on the client or the server?

Both. Client-side validation gives instant feedback. Server-side validation is the one that counts, because requests can bypass the browser, and it's where you can also check DNS and disposable domains.

Try it

More guides

Block burners at sign-up.

One API call at sign-up. Burners out, real people in.

  • 7-day free trial
  • 1,000 checks included
  • No card
  • Then from $9 a month