On this page
Regex email pattern you can copy
This is the pattern most forms need. It accepts the addresses people actually type and rejects the obvious mistakes, like a missing @ or a missing domain ending.
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$It is the same pattern as the Email quick pattern in our Regex Tester, with ^ and $ added so it checks a whole field instead of finding addresses inside longer text.
Email validation regex pattern, part by part
| Part | What it matches |
|---|---|
^ | The start of the input, so nothing can come before the address |
[a-zA-Z0-9._%+-]+ | The local part (before the @): one or more letters, digits, dots, underscores, percent signs, plus signs or hyphens |
@ | One literal at sign |
[a-zA-Z0-9.-]+ | The domain, including any subdomains: letters, digits, dots and hyphens |
\. | A real dot before the ending. Without the backslash, a dot matches any character |
[a-zA-Z]{2,} | The top-level domain, such as com, de or museum: two or more letters |
$ | The end of the input, so nothing can follow the address |
If any symbol here looks unfamiliar, the regex cheat sheet covers character classes, quantifiers and anchors with examples.
Simple email regex vs a stricter one
The practical pattern sits between two other common choices. The loose one only asks for "something, an at sign, something, a dot, something":
^[^\s@]+@[^\s@]+\.[^\s@]+$The stricter one keeps dots from starting, ending or doubling in the local part, checks each domain label, and also allows the apostrophe found in names like O'Brien:
^[A-Za-z0-9_'+%-]+(?:\.[A-Za-z0-9_'+%-]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\.)+[A-Za-z]{2,}$Which addresses does each regex for email address accept?
Here is how the three patterns handle addresses that trip up validators. The "Valid?" column follows the email standards, not any one pattern.
| Address | Valid? | Loose | Practical | Stricter |
|---|---|---|---|---|
[email protected] | Yes | Match | Match | Match |
[email protected] | Yes, plus tag | Match | Match | Match |
[email protected] | Yes, subdomains | Match | Match | Match |
o'[email protected] | Yes | Match | No match | Match |
[email protected] | Yes, internationalized domain in ASCII form | Match | Match | Match |
josé@example.com | Only where mail servers support international addresses | Match | No match | No match |
"jane doe"@example.com | Yes, quoted local part | No match | No match | No match |
jane@[192.0.2.1] | Yes, IP address literal | Match | No match | No match |
jane@localhost | Valid syntax, not reachable on the internet | No match | No match | No match |
[email protected] | No, double dot | Match | Match | No match |
[email protected] | No, leading dot | Match | Match | No match |
[email protected] | No, empty domain label | Match | Match | No match |
[email protected] | No, label starts with a hyphen | Match | Match | No match |
jane [email protected] | No, unquoted space | No match | No match | No match |
Two things stand out. All three accept plus tags and subdomains, so if your validator rejects [email protected], its character class is missing a +. And rare but valid forms, such as quoted local parts and IP literals, fail the practical and stricter patterns. For a sign-up form that is usually the right trade.
Which one to pick: the practical pattern for most forms, the stricter one when you want fewer typos to slip through, and the loose one when you would rather never block a real person and leave the rest to a confirmation email.
How the regex for domain name labels works
The domain half of the stricter pattern is useful on its own, for example to check a domain field:
^(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\.)+[A-Za-z]{2,}$Each label between dots starts and ends with a letter or digit, may contain hyphens in the middle, and is at most 63 characters long, which is the DNS limit. The ending must be at least two letters. That last rule rejects top-level domains written in ASCII form, such as xn--p1ai. If you need those, change the ending to [A-Za-z0-9-]{2,}.
Why can't regex email validation be perfect?
Because the standard allows far more than people use, and because a correct format says nothing about delivery.
What about the RFC 5322 email regex?
The address syntax is defined in RFC 5322. It permits quoted local parts with spaces, IP address literals in square brackets, and comments in parentheses. Those comments can be nested, and a regular expression cannot count nesting depth. So the long "RFC 5322 email regex" patterns you find online are approximations too, just much longer ones that are hard to read and maintain.
The standard also allows addresses no real mail provider hands out. Matching it exactly would let through strings that will never receive mail, while a practical pattern rejects them and catches typos.
Does a valid format mean the mailbox exists?
No. [email protected] passes every pattern above, yet nobody can sign up with it and receive your mail. A regex only checks the shape of the text. To know that an address works and belongs to the person typing it, send a confirmation link and wait for the click.
Length is a separate check: none of these patterns limit the total length. A common upper bound is 254 characters for the whole address and 64 for the local part. Check it in code, as in the examples below.
How to use an email regex in JavaScript
Trim the value, check the length, then test the pattern. Leave out the g flag: with it, test() remembers where the last match ended and can return false on the next call for the same valid address.
const EMAIL_RE = /^[A-Za-z0-9_'+%-]+(?:\.[A-Za-z0-9_'+%-]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\.)+[A-Za-z]{2,}$/;
function isPlausibleEmail(value) {
const email = value.trim();
return email.length <= 254 && EMAIL_RE.test(email);
}
const input = document.querySelector('#email');
input.addEventListener('input', () => {
input.setCustomValidity(
isPlausibleEmail(input.value) ? '' : 'Please check this email address'
);
});setCustomValidity() hooks your check into the browser's own form validation, so the form will not submit and the browser shows your message.
What the HTML5 email pattern accepts
<input type="email"> already validates the format. Browsers follow the valid email address definition in the HTML standard, which the spec itself calls a willful violation of RFC 5322. It is looser than the practical pattern in two ways: it accepts jane@localhost because no dot is required after the @, and it accepts [email protected].
To require a dot in the domain, add a pattern attribute. The browser applies it to the whole value, so it needs no ^ or $:
<input type="email" id="email" name="email" required
pattern="[^@\s]+@[^@\s]+\.[^@\s]+">See MDN's page on the email input for the multiple attribute and styling of invalid fields.
How to write the email regex in Python
Email regex Python version with fullmatch
The same pattern works in Python's re module. Use fullmatch() instead of anchors: in Python, $ also matches just before a trailing newline, so "[email protected]\n" would pass a ^...$ check with re.match().
import re
EMAIL_RE = re.compile(
r"[A-Za-z0-9_'+%-]+(?:\.[A-Za-z0-9_'+%-]+)*"
r"@(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\.)+[A-Za-z]{2,}"
)
def is_plausible_email(value: str) -> bool:
email = value.strip()
return len(email) <= 254 and EMAIL_RE.fullmatch(email) is not NoneRun this on the server even when the browser already checked the field. Anyone can send a request without your form, so the server check is the one that counts. The Python re documentation lists the differences between match(), search() and fullmatch().
How to test an email regex on your own list
The table above is a starting point. Your own sign-ups are the real test, and the Regex Tester runs any of these patterns on them in your browser, so the addresses stay on your device.
- Paste your addresses into the test string, one per line.
- Paste the pattern with its flags as a literal, for example
/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/gm, over the whole pattern field. The tester takes the slashes off and switches ongandmfor you. - The
mflag makes^and$work on every line, so each valid line lights up and the counter shows how many passed. - Look for the lines that stay unhighlighted. Those are the addresses the pattern would block. Swap in the loose or stricter pattern to compare.
Want to find addresses inside a block of text instead, such as a log file? Click the Email quick pattern. It has no anchors, so it picks out every address it finds, and the match details list each one with its position.

See which of your addresses your email regex blocks
Paste your list, drop in a pattern from this post or start from the Email quick pattern, and every match is highlighted as you type.
Frequently asked questions
For most forms, ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ is a good choice. It accepts plus tags and subdomains and rejects missing parts. If you also want to block double dots and bad domain labels, use the stricter pattern from this post. No pattern is perfect, so confirm the address by email.
No. RFC 5322 allows quoted local parts, IP literals and nested comments, and nesting is beyond what a regular expression can match. Even a perfect syntax check would not tell you the mailbox exists or belongs to the user. Use a regex to catch typos, then send a confirmation email to prove the address works.
Usually the local part's character class leaves out +, as in [a-zA-Z0-9._-]+. Add it: [a-zA-Z0-9._%+-]+. If the class is right, check how the value arrives: in a URL-encoded query string a plus sign is decoded as a space, so the server sees a space instead of a plus.
Both. The client check gives instant feedback while the user types and saves a round trip. The server check is the one you can trust, because anyone can skip your form and send a request directly. Use the same pattern in both places so they never disagree about an address.
Partly. type="email" checks the format in the browser and brings the right mobile keyboard, but it accepts addresses like jane@localhost with no dot in the domain. Add a pattern attribute if you need that rule, and always check again on the server, since browser validation can be bypassed.