Skip to content
uencoder
TASK

Write a robust email validation regex

Email validation regex is notoriously complex due to RFC 5322. Learn practical patterns for common use cases and their limitations.

  1. 1

    Email validation is complex because RFC 5322 allows many valid formats (comments, quoted strings, IP addresses in brackets). A practical regex balances strictness and usability. For most applications, a moderate pattern is sufficient: ^[^\s@]+@[^\s@]+\.[^\s@]+$ checks basic structure (non-empty [email protected]).

  2. 2
    Regex Tester →

    Test email patterns. Simple: ^[^\s@]+@[^\s@]+\.[^\s@]+$ catches obvious errors. Moderate: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ is more specific. Test against valid emails ([email protected], [email protected]) and invalid ones (missing @, spaces, no TLD).

  3. 3
    Text Extract Emails →

    Extract email addresses from text. This tool finds all email-like patterns in a text block. Use it to validate that your regex finds the same emails — compare results to verify correctness.

Frequently asked questions

Should I use regex to validate emails?
For basic syntax checking, a simple regex is fine. For full RFC 5322 compliance, regex is impractical (the pattern is enormous). The best approach: use a simple regex for syntax, then send a verification email to confirm the address exists and is accessible. No regex can verify that an email is deliverable.
What does the perfect email regex look like?
There is no perfect email regex. RFC 5322 allows formats that no practical regex handles (e.g., "very.(),:;<>[]\".VERY.\"very@\ \"very\".unusual"@strange.example.com). The RFC 5322 regex is over 6KB. Use a library or a simple pattern + verification email instead.

Workflows that solve this

Learn more

Want to understand why?

Related tools