Regex Tester & Debugger→Specialized Version
šŸ”

Email Regex Tester

Email regex

//g
Flags:
Examples:

Email Regex Tester

Test and validate email address patterns with regular expressions. From simple validation to RFC-compliant patterns.

Email Regex Patterns

LevelPatternUse Case
Simple^[^@]+@[^@]+$Has @ sign
Basic^[\w.-]+@[\w.-]+\.[a-z]{2,}$Common validation
StrictSee RFC patternFull 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

EmailSimpleStandardNotes
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

Frequently Asked Questions

What is the best regex for email validation?

For most purposes: ^[\\w.-]+@[\\w.-]+\\.[a-z]{2,}$ is sufficient. It catches 99% of valid emails and rejects obvious errors. Perfect RFC 5322 compliance requires an extremely complex pattern. For true validation, send a verification email.

Why does my email regex reject valid emails?

Common issues: 1) Not allowing + (plus addressing), 2) TLD too restrictive (only .com, .org), 3) Not allowing dots in local part, 4) Case-sensitive without /i flag. Test with edge cases like user+tag@example.museum to ensure flexibility.

Should I use a regex library for email validation?

For basic form validation, a simple regex works. For critical applications (mail servers, user registration), use a battle-tested library like email-validator (Node.js) or validate_email (Python). They handle edge cases and stay updated with new TLDs.

Related Tools

Explore other tools you might find useful:

Related Calculators