Skip to content

Email Validation Regex: A Practical Guide for Developers

A working email validation regex, why no pattern can prove an address exists, and what to add after the regex check.

Nov 16, 2026 5 min read 1,117 words
Email Validation Regex: A Practical Guide for Developers
Email validation regex: a practical guide for developers
Email validation regex: a practical guide for developers

An email validation regex is the first check most sign-up forms run. It is quick, it runs in the browser, and it catches obvious typos. It is also easy to get wrong. Some patterns reject real addresses. Others accept a@b and call it fine.

This guide gives you a pattern you can copy, explains why it is deliberately simple, and shows what to add after the regex so bad addresses do not reach your list.

What an email validation regex can and cannot do#

A regular expression checks the shape of a string. That is all. It can tell you that jane@example.com looks like an address. It cannot tell you that Jane exists, that the domain accepts mail, or that the mailbox is not full.

Think of the regex as a spell check. It catches jane@@example.com and jane example.com. It will not catch jane@exmaple.com, which is shaped correctly and goes nowhere.

That split decides how you build validation. Use the regex for fast feedback. Use other checks to learn if the address works.

The standard says more than you think#

The formal syntax for addresses lives in RFC 5322. It allows quoted strings, comments and odd characters that nobody uses in practice. A regex that follows it to the letter is huge and hard to read.

The people who wrote the HTML specification chose a simpler path. Their valid email address definition is what browsers use for <input type="email">, and the spec itself calls it a "willful violation" of RFC 5322. Their reasoning is that the RFC is too strict before the @, too vague after it, and too loose about comments and whitespace to be practical on a web form.

You can learn from that. A short, readable pattern that you fully understand beats a monster pattern that nobody dares to touch.

A regex you can copy#

This is the pattern from the HTML specification:

const EMAIL_RE =
  /^[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])?)*$/

function looksLikeEmail(value) {
  return EMAIL_RE.test(value.trim())
}

It breaks down into three parts:

  • Local part: one or more letters, digits or the allowed symbols, before the @.
  • The @ sign: exactly one.
  • Domain: labels of up to 63 characters, separated by dots, with no hyphen at the start or end of a label.

Two things it does not do. It accepts a@b, because a bare host name has no dot. It also rejects non-ASCII characters, so addresses with accented letters or other scripts fail. If your audience writes in many languages, test that case and decide what you want.

Add a length check#

Regex length limits are clumsy, so check length in code. The SMTP standard, RFC 5321, sets the local part at 64 octets, the domain at 255, and the whole path at 256 including brackets. In practice that means a full address should not pass 254 characters.

function isValidLength(email) {
  const [local, domain] = email.split('@')
  return email.length <= 254 && local.length <= 64 && domain.length <= 255
}

Common email validation regex mistakes#

Most bad email validation regex patterns fail in the same ways:

  • Blocking the plus sign. jane+news@example.com is valid and many people use it to filter mail.
  • Limiting the top-level domain to three letters. Domains such as .technology and .photography exist, and new ones appear often.
  • Requiring a dot in the local part. Many valid addresses have none.
  • Forcing lowercase. Case rules apply to the domain in practice. Store the address as the user typed it, and compare in lowercase.
  • Trimming nothing. A trailing space from a paste fails the match. Trim first.

What to check after the regex passes#

A passing email validation regex is step one. Add these checks in order, from cheapest to most expensive.

  1. Typo hints. Compare the domain against common ones. If someone types gmial.com, suggest gmail.com.
  2. Disposable domains. Flag addresses from throwaway mail services if they hurt your sign-up quality.
  3. DNS and MX lookup. Confirm the domain has mail servers. A domain without them cannot receive mail.
  4. Mailbox check. Ask the receiving server if the mailbox exists, without sending a message.
  5. Confirmation email. For accounts, send a link and wait for the click. It is the only proof that the user owns the address.

Steps three and four need network access, and mail servers can be slow, strict or deliberately vague. That is why most teams call a service for them. Tomba's email verifier runs these checks, and the Tomba API lets you call it from your own sign-up flow. For a quick manual test, try the free email checker.

Where to run each check#

Not every check belongs in the browser.

Check Browser Server
Regex shape Yes, for instant feedback Yes, always repeat it
Length limits Yes Yes
Typo suggestions Yes Optional
MX lookup No Yes
Mailbox check No Yes, through an API
Confirmation email No Yes

Never trust the browser alone. Anyone can skip your front-end and post straight to your API, so the server must repeat the regex check.

Handling results kindly#

Validation is a user experience problem too. A few habits help:

  • Show the error next to the field, in plain words.
  • Offer a fix for likely typos, and let the user keep what they typed.
  • Do not block on "unknown" results. Some servers accept all mail, and a verifier cannot be sure. The catch-all verifier covers this case.

If you collect addresses in bulk, such as from a CSV, run the file through bulk tasks instead of writing loops of your own.

FAQ#

What is the best email validation regex?#

There is no perfect one. The pattern in the HTML specification is a safe, readable choice for web forms. Pair it with length checks and a confirmation email.

Can a regex prove an email address exists?#

No. A regex checks shape only. To learn if a mailbox exists, you need a DNS lookup and a mailbox check, or a verification service.

Why does my email validation regex reject valid addresses?#

Usual causes are a blocked plus sign, a short top-level domain rule, or a ban on non-ASCII characters. Test your pattern against a list of unusual but valid addresses.

Should I validate email on the client or the server?#

Both. The client gives fast feedback. The server is the real gate, because users and bots can skip the client.

Is a@b a valid address?#

By the formal rules a host name without a dot can be valid inside a private network, but on the public internet you almost never want it. Most forms require at least one dot in the domain.

// 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

Share
0 clapsEnjoyed it? Give a clap.
AU

// about the author

Tomba Editorial Team

Was this helpful?