Practical email validation for modern applications. Balances common address formats with strict length, dot and domain rules. Supports plus addressing, long TLDs and ASCII internationalized domains that simpler patterns may reject. Includes named captures and extensive tests. A practical fit for most SaaS signups, contact forms and contact management. Rules neither too loose nor too strict.
+ signs. Trailing dots and consecutive dots are rejected._, - or ', but must contain a letter or digit.xn-- domain forms for internationalized names.local_part, username, plus_alias, domain.The regex checks for the xn-- structure, not full IDNA validity
Narrower patterns may reject some of these valid email address formats.
| Accepted example | What it demonstrates |
|---|---|
user.name@example.com | Common dotted username |
User.Name@Example.Com | Mixed case |
o'connor@example.com | Apostrophe in the username |
_support-@example.com | Permitted username edges |
user+news@example.com | Plus addressing |
user+@example.com | Empty plus tag |
user+news+work@example.com | Additional plus signs |
user@example.technology | Longer TLD |
user@xn--bcher-kva.de | Internationalized domain in ASCII |
Loose patterns may accept some of these malformed email addresses or input formats.
| Rejected example | Reason |
|---|---|
.user@example.com | Leading local-part dot |
user.@example.com | Trailing local-part dot |
user..name@example.com | Consecutive local-part dots |
user@example..com | Empty domain label |
user@_example.com | Underscore in the domain |
user@-example.com | Leading domain-label hyphen |
user@name@example.com | Multiple @ signs |
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@example.com | Local part exceeds 64 characters |
user name@example.com | Space in local part |
User Name <user@example.com> | Display-name wrapper, not a bare address |
user@example.com,other@example.com | Address list, not one address |
Tabs, CR/LF, control characters and surrounding text are also rejected.
These policy exclusions include standards-valid forms; they are not inherently unsafe. See RFC 5321
| Excluded case | Example |
|---|---|
| IP-literal domain | user@[127.0.0.1] |
| Single-label domain | user@localhost |
| Quoted local part | "user"@example.com |
| Raw Unicode address | 名前@example.com |
Extra local-part symbols: !, %, /, = | user%name@example.com |
| Punctuation-only username | ___@example.com |
| Apostrophe inside a plus tag | user+new's@example.com |
Username dot immediately before + | user.+news@example.com |
Verified against 560 test cases, covering valid and invalid forms, length boundaries, aliases, domains, case and control characters.
Length guards and dot-separated segments limit ambiguity associated with catastrophic backtracking
Rejecting control characters reduces log-injection risks. Still use server-side validation, safe mail APIs, parameterized queries, output encoding and email verification. Regex cannot prove domain existence, mailbox ownership or deliverability, or prevent injection alone. See OWASP guidance
Measured across all the test suite: median of seven batch averages, precompiled regex. Speed depends on hardware, engine and input.
| Engine | Duration per validation |
|---|---|
| Node.js 24.19 | ~0.13 µs |
| Ruby 3.2.2 | ~0.92 µs |
About regex101.com performance: Change the Unit Tests tab to "Show only failed tests" to improve the tests speed.
Use the JavaScript flavor without flags.
To enforce whole-string matching for Ruby/PCRE2 ^ with \A and both $ anchors with \z (one inside the length lookahead and one at the end). Other flavors may need syntax changes.