Regex for US ZIP Code
Validates US ZIP codes in 5-digit or ZIP+4 format.
Pattern
/^\d{5}(-\d{4})?$/ Live Tester
Enter a string to test
Examples
✓ 10001
✓ 90210
✓ 12345-6789
✗ 1234
✗ 123456
✗ ABCDE
Pattern Breakdown
^\d{5} — five digits
(-\d{4})?$ — optional dash + four more digits
Code Snippets
Javascript
const regex = /^\d{5}(-\d{4})?$/;
regex.test("90210"); // true Python
import re
pattern = r"^\d{5}(-\d{4})?$"
bool(re.match(pattern, "90210")) # True Php
$pattern = '/^\d{5}(-\d{4})?$/';
preg_match($pattern, "90210"); // 1 Related Patterns
Email Address /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/ URL /^https?:\/\/(www\.)?[a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([a-zA-Z0-9()@:%_+.~#?&/=-]*)$/ Phone Number (International) /^\+?[1-9]\d{1,14}$/ Phone Number (US) /^\(?[2-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/ Phone Number (EU) /^\+?[1-9][0-9]{0,3}[\s.-]?\(?[0-9]{1,5}\)?[\s.-]?[0-9]{1,5}[\s.-]?[0-9]{1,5}$/ IPv4 Address /^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/
Frequently Asked Questions
What is the regex for US ZIP Code?▾
The regex pattern for US ZIP Code is /^\d{5}(-\d{4})?$/. Validates US ZIP codes in 5-digit or ZIP+4 format.
How do I use the US ZIP Code regex in JavaScript?▾
In JavaScript you create the pattern with a regex literal or the RegExp constructor and call .test() to check a string against it. A ready-to-copy example is shown in the Code Snippets section above, alongside Python and PHP versions.
What does the US ZIP Code pattern match?▾
It matches strings like 10001; it rejects strings like 1234. See the Examples section above for the full list of matching and non-matching cases.