DevTools
Back to Regex Tester

US ZIP Code Regex Pattern

Match and validate US ZIP codes in 5-digit and ZIP+4 formats using regex. Ready-to-use patterns for address validation.

The Pattern

/\b\d{5}(?:-\d{4})?\b/g

How It Works

TokenMeaning
\bWord boundary to prevent partial matches
\d{5}Exactly 5 digits (standard ZIP code)
(?:-\d{4})?Optional ZIP+4 extension: dash followed by 4 digits
\bTrailing word boundary

Test Cases

90210Match
10001Match
90210-1234Match
00501Match
1234No match
123456No match
ABCDENo match

Code Examples

javascript
const zipRegex = /\b\d{5}(?:-\d{4})?\b/g;
const text = "Ship to 90210 or 10001-5432 for delivery.";
const matches = text.match(zipRegex);
console.log(matches); // ["90210", "10001-5432"]
python
import re
zip_regex = r'\b\d{5}(?:-\d{4})?\b'
text = "Ship to 90210 or 10001-5432 for delivery."
matches = re.findall(zip_regex, text)
print(matches)  # ['90210', '10001-5432']

Common Use Cases

Related Patterns

Want to test this pattern with your own data?

Try this pattern in Regex Tester →