Regex Pattern for Email Validation
Email validation regex is one of the most commonly written and miswritten patterns in software. This example provides a practical pattern that accepts the vast majority of real email addresses while rejecting obvious invalid inputs. Test it against edge cases like subdomains, plus-addressing, and long TLDs. Remember that the only true email validation is sending a confirmation message.
Example
/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}$/
# Test cases (one per line):
[email protected]
[email protected]
invalid-email
missing@tld
@nodomain.com
[email protected]FAQ
- Why is email regex unreliable?
- The full email specification (RFC 5321) allows characters and formats most regex patterns do not cover. Use regex for basic sanity checks but always send a confirmation email to verify deliverability.
- Should I allow plus-addressing in emails?
- Yes. Addresses like [email protected] are valid and widely used for filtering. Make sure your regex includes + in the allowed characters before the @ sign.
- How do I test my regex against multiple inputs?
- Enter each test email on a separate line in the test string area. The tester highlights matches and non-matches so you can verify each case at a glance.
Related Examples
Regex Pattern for URL Matching
Matching URLs reliably requires handling protocols, domains, ports, paths, query...
Regex Pattern for Phone NumbersPhone numbers appear in dozens of formats: with country codes, spaces, dashes, d...
Regex Pattern for Password StrengthPassword strength requirements are commonly enforced with a series of lookahead ...