You are writing a signup form and need an email regex that does not reject real users or accept garbage. Here are the patterns that work in production, with honest notes on what they miss and when to use something else.
| Pattern Name | Regex | Catches | Misses |
|---|---|---|---|
| Simple (recommended) | ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$ | 99%+ of real emails | Quoted local parts, IP domains |
| Strict TLD | ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,63}$ | Same + caps TLD length | Same as simple |
| With subdomains | ^[a-zA-Z0-9._%+-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$ | [email protected] | Quoted local parts |
| Ultra-permissive | ^.+@.+\\..+$ | Everything with @ and a dot | Almost nothing — too loose |
Use the simple pattern. It catches the real emails your users type. Do not use the RFC 5322 regex (it is 6,300+ characters long). No one has an email address that needs it. Send a confirmation email instead — that is the real validation.
Taking the recommended pattern apart:
^ — start of string (nothing before the email)[a-zA-Z0-9._%+-]+ — local part: letters, digits, dots, underscores, percent, plus, hyphen (one or more)@ — the literal @ symbol[a-zA-Z0-9.-]+ — domain: letters, digits, dots, hyphens\. — literal dot before TLD[a-zA-Z]{2,} — TLD: 2 or more letters (.com, .uk, .museum, .photography)$ — end of string (nothing after the email)Test this pattern with your real user data before shipping it.
| Format | Regex | Example Matches |
|---|---|---|
| US flexible | ^\\+?1?[-.\\s]?\\(?\\d{3}\\)?[-.\\s]?\\d{3}[-.\\s]?\\d{4}$ | (555) 123-4567, 555-123-4567, +1 555 123 4567 |
| US strict (10 digits) | ^\\d{3}-\\d{3}-\\d{4}$ | 555-123-4567 only |
| US digits only | ^\\d{10}$ | 5551234567 |
| International E.164 | ^\\+[1-9]\\d{6,14}$ | +14155551234, +442071234567 |
| With extension | ^\\+?\\d[\\d\\s.-]{6,14}(\\s?(ext|x)\\.?\\s?\\d{1,6})?$ | +1 555-123-4567 ext 890 |
[email protected] is valid. Gmail, Outlook, and others support plus addressing for filtering. Your regex must allow + in the local part..co, .io, .ai are 2-letter TLDs. .photography is 11 letters. Use {2,} not {3}.\d{3}-\d{3}-\d{4} rejects every non-US number. Use the E.164 pattern or a phone library.\d{10} matches "call 5551234567 now" because 10 digits exist inside the string. Anchor the pattern to validate the entire input.[email protected] passes every email regex. Send a confirmation email. For phones, send an SMS code. Regex checks format, not existence.Copy any pattern above, open the Regex Tester, and paste it. Then paste these test strings to check edge cases:
If your pattern rejects a valid input or accepts an invalid one, adjust before deploying. Five minutes of testing saves hours of debugging user complaints.
Test your email and phone regex patterns before they hit production.
Open Regex Tester