Email regex
A tested email regex that accepts real-world addresses (plus signs, subdomains, long TLDs) and rejects obvious junk. With test cases and code.
Pattern
/^[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}$/Matches
ada@example.comgrace.hopper+navy@mail.co.ukx_y-z@sub.domain.io
Doesn't match
ada@@example.comada@exampleada example@x.com
Alternative: WHATWG (what <input type="email"> uses)
^[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])?)*$Notes
- The full RFC 5322 grammar allows quoted local parts and comments; almost no real system accepts them, so a practical pattern is the better trade-off.
- A regex can only check the shape. The only proof an address works is sending a confirmation email.
- The WHATWG pattern is what browsers apply to <input type="email">; note it accepts a domain without a dot (user@localhost).
Code
JavaScript
const re = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}$/;
re.test(value); // true or falsePython
import re
bool(re.fullmatch(r'[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}', value))Try it on your own input
The live tester adds the g and m flags so every line is checked separately.
Questions
Is there a perfect email regex?
No. RFC 5322 is too permissive to be useful and a regex that implements it fully is thousands of characters long. Validate the shape loosely, then confirm by email.
Does it allow plus addressing?
Yes — the local part allows + so addresses like name+tag@gmail.com pass.
More patterns
Phone number regexURL regexIP address regexDate regexTime regex (24-hour and 12-hour)UUID regexHex color regexPassword regex