Saltar al contenido
uencoder

Write un robust email validation regex

Email validation regex es notoriously complejo due a RFC 5322. Aprender practical patrones para común usar cases y sus 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
    Probador de regex →

    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
    Extractor de correos del texto →

    Extraer 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.

Preguntas frecuentes

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.

Flujos que resuelven esta tarea

Herramientas relacionadas