A little help goes a long way. Find a tool/

Developer FIELD NOTES · 4 MIN READ

How Email Validation Actually Works

The anatomy of an email address, the one regex browsers use for input type=email, what it allows and rejects, and why syntax checks are not delivery checks.

An email address is a tiny data structure with a surprisingly contested definition: a local part, an at-sign, and a domain. The full RFC 5322 grammar is famous for allowing absurdities, but browsers, forms, and most validators agree on a much simpler contract — and knowing exactly what that contract checks (and what it cannot) saves you from both false rejections and false confidence.

The anatomy: local part, at-sign, domain

Every address splits at the first at-sign into two halves. In [email protected], the local part is first.last+news and the domain is sub.example.com. The local part belongs to the mailbox owner — plus-addressing like this is a common convention for tagging incoming mail — while the domain is what mail servers actually route to. A validator that understands the shape reports all three pieces: local, domain, and whether the domain ends in a plausible top-level domain (two or more letters after a final dot). That last check matters because user@localhost or a@server are structurally fine on private networks but undeliverable on the public internet.

The one regex browsers actually use

You do not need RFC 5322 to validate a form. The HTML specification defines exactly one email-matching pattern, and every browser applies it to <input type="email">:

^[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 three moves, as How Regular Expressions Work explains: the local part is one or more characters from an allowed class — letters, digits, and the punctuation .!#$%&'*+/=?^_`{|}~-; then a single domain label must start and end with an alphanumeric, with up to 61 more alphanumerics or hyphens between (the 63-character DNS label limit); then one or more dot-separated labels must follow, which is what makes at least one dot mandatory. That final + is why user@localhost fails while [email protected] passes.

What it allows, and what it rejects

The shape is deliberately pragmatic. It accepts addresses most people would call strange — !#$%&*@example.com is valid because those characters are legal in a local part — and it rejects common typos with specific, explainable reasons: no at-sign at all, two or more at-signs, a domain with no dot, or punctuation in the wrong place. It also refuses things RFC 5322 technically permits: quoted local parts like "john smith"@example.com, comments in parentheses, and IP-literal domains like user@[192.168.0.1]. Those edge cases exist in the RFC but almost never in real mailboxes, and a form that accepts them creates support tickets, not happy users. Case is a non-issue: local parts are technically case-sensitive, but in practice every mailbox treats [email protected] and [email protected] the same.

Validation is not verification

The deepest mistake is confusing "valid" with "real". A syntactically perfect address can belong to nobody: the domain may have no mail exchanger (MX) record, the mailbox may have been deleted, or the address may be a throwaway created to dodge a signup form. No regex can see any of that — delivery is a property of DNS and mail servers, not of string shape. The standard ladder of confidence goes: shape check (instant, free), domain check (does the domain exist and advertise MX records?), then confirmation email (the only proof that someone controls the inbox). Signup forms should run the cheap check instantly and reserve the expensive check for the moment it matters, which is why "confirm your address" emails remain the only technique that verifies anything at all.

When to reject, when to accept

Use the browser-grade pattern everywhere an address enters your system, and report why something failed — "missing an @ symbol" is actionable, "invalid" is not. Accept the plus-tagging and dot conventions users rely on for filtering. Be suspicious, not rejecting, of unusual-but-legal local parts. And never "fix" an address silently: lowercasing the domain is safe, but rewriting a local part can redirect someone's mail to a stranger. Validation's job is to catch typos at the door — verification's job is everything after.

Try it yourself

Type any address into the Email Validator — it applies the browser-grade pattern, splits the address into local part and domain, flags a missing top-level domain, and reports a plain-English reason for every rejection. Paste the regex above into the Regex Tester to watch which test addresses it catches, and feed any piece of it to the Regex Explainer for a token-by-token explanation of what each bracket and quantifier means.

Frequently asked questions

What is the correct regex for email validation?
Use the one from the HTML specification that browsers apply to input type=email: an allowed-character class for the local part, an at-sign, then dot-separated domain labels of up to 63 characters each. It rejects garbage without the RFC 5322 grammar's exotic legal cases, which is the right trade-off for forms.
Why does user@localhost fail validation?
Because the browser-grade pattern requires at least one dot-separated label after the at-sign — a public email domain must end in a top-level domain of two or more letters. Bare single-label hosts exist on private networks, but they are undeliverable from the internet, so forms treat them as invalid.
Are plus signs in email addresses valid?
Yes: [email protected] is valid, and the plus-tagged part is a convention many mail systems use for filtering. The validator splits the address at the at-sign and treats everything before it as the local part, so plus tags, dots, and other allowed punctuation pass intact.
Does a valid-looking email address mean the mailbox exists?
No. Syntax validation only checks shape; whether mail actually arrives depends on the domain's DNS records and the mailbox itself. The only reliable verification is a confirmation email — everything else, including domain lookups, narrows the odds without proving anything.
Should I lowercase email addresses before storing them?
Lowercase the domain, always — DNS is case-insensitive. The local part is technically case-sensitive, but real-world mail systems treat it insensitively, so normalizing the whole address to lowercase matches practice. Never rewrite the local part beyond casing, or you may redirect someone else's mail.