Aarunya AppsAarunya Apps

US ZIP CodeRegex — Pattern, Examples & Code

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

What it matches / doesn't match

Matches ✅Does not match ❌
902101234
10001-1234902100
005019021A

How it works

Matches standard 5-digit US ZIP codes and the extended ZIP+4 format with a hyphen and four additional digits. The ZIP+4 group is optional, so both 90210 and 90210-3456 match. Purely numeric — it does not validate whether the ZIP code actually exists in the USPS database.

Code Usage

JavaScript

const regex = /^\d{5}(?:-\d{4})?$/;
regex.test("90210"); // true

Python

import re
pattern = re.compile(r'^\d{5}(?:-\d{4})?$')
bool(pattern.match("90210"))  # True

Go

import "regexp"
r := regexp.MustCompile(`^\d{5}(?:-\d{4})?$`)
r.MatchString("90210") // true

Need a custom regex for a different use case?

Generate a custom regex with AI →

FAQ

What does the US ZIP Code regex pattern match?

Matches standard 5-digit US ZIP codes and the extended ZIP+4 format with a hyphen and four additional digits. The ZIP+4 group is optional, so both 90210 and 90210-3456 match. Purely numeric — it does not validate whether the ZIP code actually exists in the USPS database.

How do I use the US ZIP Code regex in JavaScript?

const regex = /^\d{5}(?:-\d{4})?$/; regex.test("90210"); // true

Can I use the US ZIP Code regex in Python?

Yes. import re pattern = re.compile(r'^\d{5}(?:-\d{4})?$') bool(pattern.match("90210")) # True