Regex for Email Address
This regex matches standard email addresses as defined by most practical implementations. It checks for a local part containing alphanumeric characters, dots, underscores, percent signs, plus signs, and hyphens, followed by an @ symbol, a domain name, and a top-level domain of at least two characters. While it does not cover every edge case in RFC 5322, it handles the vast majority of real-world email addresses correctly.
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ What is the regex pattern for Email Address?
The regex pattern for Email Address is ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ with the i flag. This regex matches standard email addresses as defined by most practical implementations. It checks for a local part containing alphanumeric characters, dots, underscores, percent signs, plus signs, and hyphens, followed by an @ symbol, a domain name, and a top-level domain of at least two characters. While it does not cover every edge case in RFC 5322, it handles the vast majority of real-world email addresses correctly. This pattern is commonly used for form validation and data extraction from text.
Test Examples
user@example.com user@example.com jane.doe+work@company.co.uk jane.doe+work@company.co.uk not-an-email Common Uses
- ✓ Form validation
- ✓ Data extraction from text
- ✓ Email list cleaning
- ✓ Contact form input verification
Variations
Simple email
\S+@\S+\.\S+ Minimal check, allows many invalid formats
RFC 5322 compliant
(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]) Full RFC 5322 compliance, rarely needed in practice
With specific TLDs
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.(com|org|net|edu|gov)$ Only matches specific top-level domains
Frequently Asked Questions
Does this regex validate all valid email addresses?
No. The full RFC 5322 email spec allows many unusual formats like quoted strings and IP address domains. This regex covers the vast majority of real-world addresses and is suitable for form validation, but it will reject some technically valid edge cases.
Should I use regex alone to validate email addresses?
Regex is good for a first-pass check, but the only way to truly validate an email is to send a confirmation message. Use regex for format validation, then verify deliverability with a confirmation email.
Why does this regex allow plus signs in the local part?
Many email providers like Gmail support plus addressing (e.g., user+tag@gmail.com) for filtering. The plus sign is a valid character in the local part of an email address per the RFC spec.