# Regex for US ZIP Codes

> US ZIP code regex matching 12345 and ZIP+4 (12345-6789). Token-by-token breakdown, examples, and why a format check can't prove a ZIP code exists.

```
/^\d{5}(?:-\d{4})?$/
```

US ZIP codes are five digits, optionally followed by a hyphen and the four-digit ZIP+4 add-on. The group makes the extension all-or-nothing, so a dangling hyphen or a short suffix fails.

## Token by token

| Token | Meaning |
|---|---|
| `^` | start of string |
| `\d{5}` | exactly five digits |
| `(?:-\d{4})?` | optionally, a hyphen and four more digits (ZIP+4) |
| `$` | end of string |

## Examples

- ✓ matches: `90210`
- ✓ matches: `10001-1234`
- ✓ matches: `02134`
- ✗ does not match: `9021`
- ✗ does not match: `90210-`
- ✗ does not match: `90210-12`

## Variations

- `^\d{5}(?:[-\s]?\d{4})?$` — also accept a space, or no separator, before the +4
- `^\d{5}$` — five-digit ZIP codes only

## Language notes

- In Python 3 and .NET, \d also matches digits from other scripts by default. Use [0-9], or Python's re.ASCII flag, for strict ASCII.

## FAQ

### Why keep ZIP codes as strings?

Codes in New England start with 0 — 02134 is in Boston. Store them as strings, never numbers, or the leading zero disappears.

### Does a match mean the ZIP code exists?

No — 00000 matches. To confirm a real ZIP code, check it against USPS data or an address-validation service.

## Related patterns

- [Regex for UK Postcodes](https://www.devkult.com/regex/uk-postcode.md)
- [Regex for Phone Number Validation](https://www.devkult.com/regex/phone-number.md)
- [Regex for Numbers Only (Digits)](https://www.devkult.com/regex/digits-only.md)

Open the interactive page: https://www.devkult.com/regex/us-zip-code