//g
  • 100% Free
  • No Sign-Up
  • No Credit Card
  • No Free Trial
  • No Pro Tier
  • No Watermarks

Nothing is uploaded. Just open it and start.

US ZIP Code Regex

A five-digit US ZIP code, optionally followed by a hyphen and the four-digit ZIP+4 extension.

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

Piece by piece

  1. ^the start of the text
  2. \d{5}a digit (0–9), repeated exactly 5 times, as many as possible
  3. (?:a group (not captured)
  4. -the character “-”
  5. \d{4}a digit (0–9), repeated exactly 4 times, as many as possible
  6. )?end of the group, repeated optionally (0 or 1 time), as many as possible
  7. $the end of the text

Examples

TextResult
94105Matches
10001-1234Matches
9410Doesn't match
941051Doesn't match
94105-12Doesn't match
ABCDEDoesn't match
  • It doesn't check that the code is in use.

Other common patterns

Test any regular expression →

Frequently asked questions

How do I use this us zip code regex in JavaScript?
Write it as /^\d{5}(?:-\d{4})?$/ and call re.test(text). It is anchored with ^ and $, so it checks the whole text; remove them to find it inside longer text (and add the g flag to find every one). The Code view writes it out for Python, Go and PHP too.
Is it a complete validator?
No regex is the whole story. It doesn't check that the code is in use.
Can I try it on my own text?
Yes. The tester above already holds the examples; paste your own text over them and every match is highlighted as you type. Nothing is uploaded.

Spotted a bug or have a suggestion?

Found something broken, have an idea, or just want to say thanks about any of our tools? Every message reaches a real person.