PatternRegex
Match an email address
A practical email regex for forms, logs and text — strict enough to catch typos, loose enough to accept real addresses like dev+ops@mail.co.uk.
Last updated
Matches
- ada@example.com
- dev+ops@mail.co.uk
- grace.h_92@sub.domain.io
Doesn’t match
- plainaddress
- name@nodot
- @nobody.com
Why it’s written this way
The local part [a-zA-Z0-9._%+-]+ accepts the characters real providers actually allow — including + for the subaddressing Gmail and Fastmail users rely on. Patterns that forget the plus sign silently reject working addresses, and that is the most common bug in homemade email regex.
The domain side requires at least one dot and a two-plus letter ending via \.[a-zA-Z]{2,}. That rejects bare hostnames like user@localhost, which is almost always what you want in a public-facing form.
Edge cases to know
- →It accepts consecutive dots (a..b@x.com), which are technically invalid — tightening that costs a lot of pattern for a case that barely occurs in real data.
- →It is not RFC 5322. The full grammar allows quoted spaces and comments that no signup form should accept.
- →The only real validation is a confirmation email. Use this to catch typos at the form, not as proof the mailbox exists.