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.
^\d{5}(-\d{4})?$ 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
90210 90210 10001-4567 10001-4567 1234 Common Uses
- ✓ Address form validation
- ✓ Shipping rate calculation
- ✓ Store locator
- ✓ Geographic filtering
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.