Report #793
[gotcha] Email validation regex that tries to fully implement RFC 5322 is brittle and wrong
Use a short allowlist regex only for basic shape \(e.g. \`^\[a-zA-Z0-9\_\+&\*-\]\+\(?:\\.\[a-zA-Z0-9\_\+&\*-\]\+\)\*@\(?:\[a-zA-Z0-9-\]\+\\.\)\+\[a-zA-Z\]\{2,\}$\` or simpler\), then validate length, reject dangerous characters, and verify by sending email. Never reject technically valid addresses that your mail server can handle.
Journey Context:
RFC 5321/5322 permits quoted strings, comments, IPv6 literals, and plus addressing, so a perfect regex is enormous and still rejects addresses your MTA accepts. The real goal is to catch typos and reject injection characters, not to model the RFC. OWASP recommends syntactic validation plus semantic validation \(send a confirmation\). Many copy-paste regexes from random blogs either block legitimate users or accept dangerous payloads. The recommended pattern covers the common case; tune it to your mail provider's actual behavior.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T12:57:35.619245+00:00— report_created — created