Skip to content

Regex for US ZIP Code

This regex matches US ZIP codes in both the standard 5-digit format and the extended ZIP+4 format with an optional dash and four additional digits. ZIP codes are used by the US Postal Service for mail delivery routing. The 5-digit code identifies a delivery area, and the optional +4 extension narrows it to a specific delivery segment.

Pattern
^\d{5}(-\d{4})?$
Test this pattern in the Regex Tester →

What is the regex pattern for US ZIP Code?

The regex pattern for US ZIP Code is ^\d{5}(-\d{4})?$. This regex matches US ZIP codes in both the standard 5-digit format and the extended ZIP+4 format with an optional dash and four additional digits. ZIP codes are used by the US Postal Service for mail delivery routing. The 5-digit code identifies a delivery area, and the optional +4 extension narrows it to a specific delivery segment. This pattern is commonly used for address form validation and shipping rate calculation.

Test Examples

Match
90210
Matches: 90210
Match
10001-4567
Matches: 10001-4567
No Match
1234

Common Uses

Variations

5-digit only

^\d{5}$

Only the base 5-digit format

ZIP+4 required

^\d{5}-\d{4}$

Requires the full ZIP+4 format

With optional space

^\d{5}([- ]\d{4})?$

Allows space instead of dash before +4

Frequently Asked Questions

What is a ZIP+4 code?

ZIP+4 adds four digits after the base 5-digit ZIP code, separated by a hyphen. The extra digits narrow the delivery location to a specific block, building, or PO box, enabling more precise mail routing.

Does this validate that the ZIP code actually exists?

No, it only checks the format. ZIP codes range from 00501 to 99950, but not all 5-digit combinations are assigned. Use the USPS API for authoritative ZIP code validation.

Are ZIP codes numeric only?

Yes, US ZIP codes use digits only. This distinguishes them from postal codes in countries like the UK and Canada, which use alphanumeric codes.

Related Patterns

UK Postal Code

^[A-Z]{1,2}\d[A-Z\d]?\s?\d[A-Z]{2}$

Canadian Postal Code

^[A-CEGHJ-NPRSTVXY]\d[A-CEGHJ-NPRSTV-Z]\...

US Phone Number

^\+?1?[-.\s]?\(?\d{3}\)?[-.\s]?\d{3}[-.\...

Related Reading

Regex Cheat Sheet with Examples for Developers → URL Encoding Special Characters →