What Is the Best Regex for Email Validation? Practical Patterns and Limitations
Short answer: start with a whole-string shape check such as ^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$ when you only need a lightweight form filter. Use a stricter practical pattern when you also want to reject spaces, malformed domain labels, and domains without a dot. Neither pattern can prove that a mailbox is real, accepts mail, or belongs to the person who entered it.
Quick answer: choose the pattern by policy
| Use case | Pattern | Example |
|---|---|---|
| Simple form filter | ^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$ | [email protected] |
| Practical ASCII email check | ^[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])?)+$ | [email protected] |
| Unicode-aware workflow | Normalize and validate with an email parser or provider workflow | 用户@例子.中国 |
The first two expressions are text-shape filters. They are deliberately narrower than the complete address syntax described by RFC 5322. The practical pattern is intended for common ASCII addresses in web forms, not for every legal mailbox syntax.
What RegexToolBox can do for this task
RegexToolBox is an online regex tool for generating, testing, and debugging regular expressions. Its homepage provides a Generated Regex field, a Generate Regex with AI action, language code examples, a Test Content (one per line) area, and a Validate action with per-input validation results. The current page offers JavaScript, PHP, Python, Java, and C# examples. These controls help you compare how the same pattern behaves in a chosen language; they do not add mailbox verification.
Simple email regex
For a first-pass client-side check, use:
^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$ How it works
^and$require the complete input to match.[^\\s@]+allows one or more non-space, non-@characters before the separator.@requires exactly the visible separator used by this simple model.[^\\s@]+checks that a domain-like part exists.\\.requires a dot, followed by a non-empty suffix.
This expression is easy to explain and useful for preventing obvious typos. It is not a standards-complete parser: it may accept characters your product does not want, and it will not handle every quoted local part or internationalized address.
Practical ASCII email regex
For a stricter form policy that accepts common punctuation in the local part and checks each dot-separated domain label, use:
^[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])?)+$ What this practical pattern enforces
- The local part uses a common ASCII set and cannot contain spaces.
- The domain starts and ends each label with an alphanumeric character.
- Internal domain hyphens are allowed, but a label cannot begin or end with one.
- At least one dot separates the domain labels.
- The anchors prevent a valid-looking substring from hiding extra characters.
The pattern does not implement every rule in RFC 5322, and its ASCII character policy intentionally excludes Unicode local parts. If your product supports internationalized addresses, read RFC 6531 and use an SMTPUTF8-capable parser and mail workflow instead of extending this expression until it becomes unmaintainable.
JavaScript and Python usage
JavaScript
const emailPattern = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;
const isShapeValid = emailPattern.test(value); JavaScript regex literals do not need string escaping for the slash-delimited expression shown above. If you construct a RegExp from a string, escape backslashes for the JavaScript string as well. The MDN regular expressions guide documents the syntax and flags.
Python
import re
email_pattern = re.compile(r"^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$")
is_shape_valid = email_pattern.fullmatch(value) is not None A raw Python string keeps the backslash readable. fullmatch() makes the whole-value intent explicit; the anchors are retained so the same pattern can be copied into other engines. The Python re documentation describes the engine and matching methods.
Valid and invalid test set
Paste one value per line into RegexToolBox's Test Content (one per line) field, select the language if you want generated code, and click Validate. The table below targets the practical ASCII pattern unless noted otherwise.
| Input | Expected | Reason |
|---|---|---|
[email protected] | Valid | Common local part and two domain labels |
[email protected] | Valid | Plus sign in the local part and a subdomain |
[email protected] | Valid | Dots in the local part and multiple domain labels |
[email protected] | Valid | Underscore in local part and internal domain hyphen |
missing-at.example.com | Invalid | No @ separator |
user@ | Invalid | No domain labels |
user@example | Invalid | No dot under this practical policy |
user @example.com | Invalid | Whitespace is not accepted |
[email protected] | Pattern-dependent | The simple pattern accepts it; stricter mailbox policy may reject consecutive dots |
用户@例子.中国 | Invalid for ASCII pattern | Requires an internationalized-email workflow |
Why regex cannot prove an email address exists
A successful match only says that the characters fit the chosen expression. It cannot establish that the domain has DNS mail records, that the mailbox is assigned, that the server will accept delivery, or that the user controls the address. Even an SMTP probe can be blocked or misleading. For account creation, send a confirmation link or code and treat verified ownership as a separate application state.
Keep the regex at the input boundary, normalize where your product policy allows it, and perform the real verification through a confirmation message. Store the original address when you need auditability; do not silently rewrite user data based on assumptions about provider rules.
References and limitations
- RFC 5322 defines Internet Message Format syntax, including address forms that are broader than most web-form policies.
- RFC 6531 specifies SMTP extensions for internationalized email addresses.
- MDN: HTML email input explains browser-level email validation and its limits.
- MDN: JavaScript regular expressions documents JavaScript syntax, escaping, and flags.
Common questions
What is the best regex for email validation?
There is no single best expression. Use the simple pattern for an obvious typo filter, the practical ASCII pattern for a defined web-form policy, and a standards-aware parser plus verification email when correctness or ownership matters.
Should I use the same regex in JavaScript and Python?
You can share the same basic pattern, but the host-language syntax differs. JavaScript commonly uses a regex literal and test(); Python commonly uses a raw string with re.fullmatch().
Does a regex prove the mailbox is real?
No. It checks text shape only. It cannot prove assignment, reachability, deliverability, or ownership.
Why does the practical pattern reject Unicode addresses?
It deliberately targets common ASCII input. Internationalized addresses require SMTPUTF8-aware handling described by RFC 6531 and should not be approximated by an ever-growing ASCII expression.
How do I test this on RegexToolBox?
Open the RegexToolBox tester, paste the pattern into Generated Regex or describe the requirement with Generate Regex with AI, add one address per line in Test Content (one per line), then click Validate and inspect each result.