US ZIP CodeRegex — Pattern, Examples & Code
^\d{5}(?:-\d{4})?$What it matches / doesn't match
| Matches ✅ | Does not match ❌ |
|---|---|
●90210 | ●1234 |
●10001-1234 | ●902100 |
●00501 | ●9021A |
How it works
Matches standard 5-digit US ZIP codes and the extended ZIP+4 format with a hyphen and four additional digits. The ZIP+4 group is optional, so both 90210 and 90210-3456 match. Purely numeric — it does not validate whether the ZIP code actually exists in the USPS database.
Code Usage
JavaScript
const regex = /^\d{5}(?:-\d{4})?$/;
regex.test("90210"); // truePython
import re
pattern = re.compile(r'^\d{5}(?:-\d{4})?$')
bool(pattern.match("90210")) # TrueGo
import "regexp"
r := regexp.MustCompile(`^\d{5}(?:-\d{4})?$`)
r.MatchString("90210") // trueNeed a custom regex for a different use case?
Generate a custom regex with AI →FAQ
What does the US ZIP Code regex pattern match?
Matches standard 5-digit US ZIP codes and the extended ZIP+4 format with a hyphen and four additional digits. The ZIP+4 group is optional, so both 90210 and 90210-3456 match. Purely numeric — it does not validate whether the ZIP code actually exists in the USPS database.
How do I use the US ZIP Code regex in JavaScript?
const regex = /^\d{5}(?:-\d{4})?$/; regex.test("90210"); // true
Can I use the US ZIP Code regex in Python?
Yes. import re pattern = re.compile(r'^\d{5}(?:-\d{4})?$') bool(pattern.match("90210")) # True
