Regex for US ZIP Codes

Regex that matches US ZIP codes in 5-digit and ZIP+4 formats. Test valid and invalid values like 90210 and 90210-1234.

Part of the free Regex Tester. Runs in your browser — nothing is uploaded.

Regex for US ZIP Codes

US postal codes are five digits, optionally followed by a hyphen and four more digits (ZIP+4). The pattern \d{5}(-\d{4})? covers both and rejects everything else.

Worked example: 5-digit and ZIP+4 values

Pattern /^\d{5}(-\d{4})?$/ — test strings

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

90210
10001-1234
1234
902101
90210-12

Result for each line

✓ match     90210
✓ match     10001-1234
✗ no match  1234
✗ no match  902101
✗ no match  90210-12

Practical tip

Keep ZIP codes as strings, never numbers. Leading zeros matter: 02134 must not become 2134.

How to use this Regex Tester

  1. 1Use the live tool above — it runs entirely in your browser and never uploads your data.
  2. 2Paste the sample from the worked example, or use your own input.
  3. 3Copy the result, then adapt the same steps in your editor, script, or pipeline.

Regex for US ZIP Codes FAQs

Why store ZIP codes as strings?

Many ZIP codes start with 0, such as 02134. Storing them as integers drops the zero and breaks addresses.

Does this validate that the ZIP exists?

No. It only checks format. To confirm a ZIP is real, use an address verification service or the USPS lookup.

More Regex Tester pages

Open the full Regex Tester tool →