Regex for US ZIP Code
Matches US ZIP codes in 5-digit format (12345) and ZIP+4 format (12345-6789).
Pattern
/^\d{5}(-\d{4})?$/Pattern Breakdown
| Token | Explanation |
|---|---|
| ^ | Start of string |
| \d{5} | Five-digit ZIP code |
| (-\d{4})? | Optional +4 extension (dash and four digits) |
| $ | End of string |
Test Examples
| Input | Match? |
|---|---|
| 90210 | Match |
| 10001-1234 | Match |
| 1234 | No match |
| 123456 | No match |
Common Use Cases
- Address form validation
- Shipping calculator input
- Location-based services
Variations
^\d{5}$5-digit ZIP only
Other Regex Patterns
Want to test this pattern with your own data?
Open the Regex Tester