Regex for Email Validation — Pattern Explained with Examples
Regex for Email Validation — Pattern Explained with Examples
DodaTech
Updated Jun 20, 2026
2 min read
Email validation is one of the most common regex use cases in web forms and user registration systems. This pattern checks for the basic structure of an email address: a local part, the @ symbol, and a domain with at least one dot-separated subdomain and a valid top-level domain.
The Pattern
/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/Pattern Breakdown
| Part | Meaning |
|---|---|
^ | Start-of-string anchor |
[a-zA-Z0-9._%+-]+ | Local part: one or more alphanumeric characters plus dots, underscores, percent, plus, and hyphens |
@ | Literal @ separator |
[a-zA-Z0-9.-]+ | Domain name: one or more alphanumeric characters, dots, and hyphens |
\. | Literal dot before TLD |
[a-zA-Z]{2,} | Top-level domain: at least two alphabetic characters |
$ | End-of-string anchor |
Matches
Does NOT Match
- @example.com
- user@.com
- user@com
- user@domain
- user space@domain.com
- user@domain..com
Language Examples
JavaScript
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
console.log(emailRegex.test('user@example.com')); // true
console.log(emailRegex.test('@example.com')); // false
Python
import re
pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
print(bool(re.match(pattern, 'user@example.com'))) # True
print(bool(re.match(pattern, '@example.com'))) # FalsePHP
$pattern = '/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/';
var_dump(preg_match($pattern, 'user@example.com')); // int(1)
var_dump(preg_match($pattern, '@example.com')); // int(0)
Common Pitfalls
- Overly strict regexes reject perfectly valid emails with plus tags or subdomains
- Very permissive patterns allow inputs like
user@comwith no TLD dot separation - Unicode email support varies — this pattern only covers ASCII
- The only truly reliable way to validate an email is to send a confirmation message
Real-World Use Cases
- User registration forms — ensure signups provide a properly structured email address
- Contact forms — validate user input before sending an automated reply
- Data import cleaning — filter invalid email entries from CSV or database exports
FAQ
Related Patterns
Regex for URL Regex for UUID
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro