Email Regex Tester
Test and validate email address patterns with regular expressions. From simple validation to RFC-compliant patterns.
Email Regex Patterns
| Level | Pattern | Use Case |
|---|---|---|
| Simple | ^[^@]+@[^@]+$ | Has @ sign |
| Basic | ^[\w.-]+@[\w.-]+\.[a-z]{2,}$ | Common validation |
| Strict | See RFC pattern | Full compliance |
Common Email Patterns
``javascript
// Simple - catches most emails
const simple = /^[\w.-]+@[\w.-]+\.[a-z]{2,}$/i;
// More complete - handles more edge cases
const standard = /^[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])?)*$/;
// HTML5 email pattern (browsers use this)
const html5 = /^[a-zA-Z0-9.!#$%&'*+/=?^_{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
// Test function
function validateEmail(email, pattern = simple) {
return pattern.test(email);
}
// Examples
validateEmail('user@example.com'); // true
validateEmail('user.name@sub.domain.com'); // true
validateEmail('user+tag@gmail.com'); // true (simple: true)
validateEmail('invalid'); // false
validateEmail('@nodomain.com'); // false
`
Valid vs Invalid Emails
| Simple | Standard | Notes | |
|---|---|---|---|
| user@example.com | ā | ā | Standard format |
| user.name@example.com | ā | ā | With dots |
| user+tag@gmail.com | ā | ā | Plus addressing |
| user@sub.example.com | ā | ā | Subdomain |
| user@123.45.67.89 | ā | ā | IP address (rare) |
| user@.com | ā | ā | Invalid domain |
| @example.com | ā | ā | No local part |
| user@example | ā | ? | No TLD (technically valid internally) |
Email Parts
`javascript
// Extract email parts
const emailPattern = /^(?[\w.+-]+)@(?[\w.-]+)\.(?[a-z]{2,})$/i;
const match = 'user.name@mail.example.com'.match(emailPattern);
if (match) {
const { local, domain, tld } = match.groups;
// local: "user.name"
// domain: "mail.example"
// tld: "com"
}
``
Email Validation Best Practices
1. Don't over-validate - Unusual but valid emails exist 2. Send verification - The only true validation 3. Allow + addressing - user+tag@gmail.com is valid 4. Accept new TLDs - .museum, .company are valid 5. Trim whitespace - Before validation