Skip to main content
Network

Email validation: what a regex can't tell you

The regex passed. The user confirmed the address by retyping it. The welcome email bounced anyway, and it was addressed to @gmai.com. That domain exists, and it does not belong to Google. Syntax checking was never the bottleneck, which is worth working through before your next signup form ships.

Syntax is the easy part

The full email grammar in RFC 5322 is enormous: quoted local parts, comments, addresses longer than most databases. Almost nobody supports all of it, and that is the right call. A mail server you can actually send through matters more than RFC purity, so the pragmatic pattern most products settle on is a short local part at a domain, with a plus sign and dots allowed in the local half. That accepts every address Gmail, Outlook, and on-prem exchange servers will deliver. It also rejects quoted monstrosities nobody would type by hand.

So a regex, or a sane validation library, gets you the syntax test. The problem is only when people stop there and call it "validation".

Syntax-valid is not deliverable

  • Typo domains. gmai.com, hotmial.com, outlok.com. All valid syntax, all registered, and some of them are parked where people's typos go. The user never sees your mail again.
  • Disposable addresses. Ten-minute mailboxes pass every syntax check and confirm nothing.
  • Nonexistent mailboxes. The domain is real, the MX records are fine, and the specific mailbox was never created.

What real verification looks like

Data-driven email checks run three layers. First the syntax, which you already do. Second, a DNS lookup for MX records on the domain, which answers whether anything can even accept mail there. Third, an actual SMTP dialogue: connect to the mail server and ask, without sending a message body, whether the recipient exists. Many servers answer this honestly. Some, the catch-all kind, answer yes to everything, which is its own warning.

The only test that proves everything

Double opt-in remains the honest check. Send a confirmation link and require a click. If the mailbox is a typo at a squatter domain, nothing arrives. If it is a burner, nobody clicks. One extra step, and every downstream list is full of addresses that have demonstrated being real.

A word about the plus tag

Gmail treats user+x and user at the same domain as the same mailbox, so it is tempting to strip the plus suffix and deduplicate. Don't. People deliberately use tagged addresses to trace who leaked or sold their email, and collapsing those aliases merges identities without consent. Deliverability tooling can use the tag as a signal. Your product should leave it.

When you need the syntax layer done right, the email validator checks structure and flags the constructs a naive pattern misses. If your job is pulling addresses out of pasted text or a CSV, email extractor does the harvesting side. And because half the bugs here start in a mailto link, mailto link generator builds those with encoded subject and body, so the click arrives with context attached.