Standard Email Validation Regex (RFC 5322 Basic)
• CronOS Team
regexemailvalidationtutorialrfc-5322
Need to generate a regex pattern?
Use CronOS to generate any regex pattern you wish with natural language. Simply describe what you need, and we'll create the perfect regex pattern for you. It's completely free!
Standard Email Validation Regex (RFC 5322 Basic)
A comprehensive guide to the RFC 5322 basic email regex pattern ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ and how it works.
Pattern Breakdown
regex
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
Components
| Component | Description | Matches |
|---|---|---|
^ | Start anchor | Ensures match from string start |
[a-zA-Z0-9._%+-]+ | Local part | One or more: letters, digits, dots, underscores, percent, plus, hyphens |
@ | Separator | Literal @ symbol |
[a-zA-Z0-9.-]+ | Domain name | One or more: letters, digits, dots, hyphens |
\. | TLD separator | Literal dot (escaped) |
[a-zA-Z]{2,} | TLD | Two or more letters |
$ | End anchor | Ensures match to string end |
Character Classes
a-zA-Z- All uppercase and lowercase letters0-9- All digits.- Literal dot (in character class, doesn't need escaping)_- Underscore%- Percent sign+- Plus sign-- Hyphen (must be at end or start of character class to avoid range interpretation){2,}- Quantifier: two or more occurrences
Examples
Valid:
user@example.comjohn.doe@company.orguser+tag@domain.co.uktest_email@sub-domain.netuser%name@example.infouser_name@example-domain.com
Invalid:
user@domain(missing TLD)@domain.com(missing local part)user@.com(missing domain)user name@domain.com(space not allowed)user@domain.c(TLD must be at least 2 characters)user@@domain.com(double @ symbol)
Implementation
JavaScript
javascript
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
emailRegex.test('user@example.com'); // true
emailRegex.test('john.doe+tag@company.org'); // true
Python
python
import re
email_regex = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
bool(re.match(email_regex, 'user@example.com')) # True
bool(re.match(email_regex, 'john.doe+tag@company.org')) # True
Go
go
emailRegex := regexp.MustCompile(`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`)
emailRegex.MatchString("user@example.com") // true
emailRegex.MatchString("john.doe+tag@company.org") // true
Limitations
- Multi-part TLDs: Doesn't match
.co.uk,.com.au(would need\.[a-zA-Z]{2,}(\.[a-zA-Z]{2,})?$) - No length validation: RFC 5322 limit is 320 characters total
- No quoted strings: Doesn't support
"user name"@example.com - No IP addresses: Doesn't allow
user@[192.168.1.1] - No comments: Doesn't support
user(comment)@example.com
When to Use
- Client-side form validation
- Basic format checking for most common email formats
- Quick validation before API calls
- When you need to support plus signs and percent signs in local part
For production, consider RFC 5322-compliant patterns or validation libraries, and always verify emails via confirmation messages.
Need to generate a regex pattern?
Use CronOS to generate any regex pattern you wish with natural language. Simply describe what you need, and we'll create the perfect regex pattern for you. It's completely free!