Regex to Match a US ZIP Code
Copy the pattern, paste your text below, and see every US ZIP it finds. Below the tester: how it accepts both 5-digit and ZIP+4 forms.
What this pattern matches
This matches a US ZIP code: five digits, optionally followed by a hyphen and the four-digit ZIP+4 extension.
How it works, part by part
\b\d{5} — exactly five digits on a word boundary.
(?:-\d{4})? — an optional hyphen and four more digits for ZIP+4.
\b — a trailing boundary so a six-digit number is not accepted.
Shape only
This validates the format, not whether the ZIP actually exists. To confirm a real, deliverable ZIP you need a postal database lookup.
FAQ
Does it match ZIP+4?
Yes. 90210-1234 matches via the optional -#### group.
Will 902101 match?
No. The word boundary rejects a six-digit run that is not a valid 5 or 5+4 shape.
Does it check the ZIP is real?
No. It only checks the format; use a postal lookup to confirm the ZIP exists.