How to Validate Email
with Regex
The practical pattern, what each part does, what it can't catch, and how to test it in your browser.
How to validate email with regex: use /^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$/ for format checking, understand what each part enforces, and always follow up with a confirmation email — because regex can only verify structure, not whether the mailbox actually exists.
The Practical Email Regex
This pattern covers the vast majority of real email addresses you'll encounter:
/^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$/
Breaking It Down
^
[a-zA-Z0-9._%+\-]+
@
[a-zA-Z0-9.\-]+
\.
[a-zA-Z]{2,}
$
JavaScript Implementation
const emailRegex = /^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$/;
function isValidEmail(email) {
return emailRegex.test(email.trim());
}
// Examples
isValidEmail('user@example.com') // true
isValidEmail('user+tag@sub.domain.io') // true
isValidEmail('notanemail') // false
isValidEmail('@nodomain.com') // false
isValidEmail('user@') // false
Python Implementation
import re
EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$')
def is_valid_email(email: str) -> bool:
return bool(EMAIL_REGEX.match(email.strip()))
What This Pattern Won't Catch
Regex validates format only. It cannot:
The rule: use regex to catch obvious typos at form submission time (missing @, no TLD), but always send a confirmation email before treating an address as verified.
Valid Addresses This Pattern Rejects
The pattern is intentionally practical rather than RFC 5322 compliant. It rejects a small set of technically valid but rarely seen addresses:
"quoted strings"@example.com— quoted local partsuser@[192.168.1.1]— IP address domainsuser@localhost— no TLD (valid for local mail servers)
These represent less than 0.01% of real-world addresses. Rejecting them is an acceptable tradeoff for a readable, maintainable pattern.
Test the Pattern in Your Browser
Paste the regex and your test addresses into the free regex tester — runs locally, no upload.
Open Regex Tester →