HomeRegex LibraryUnited States Postal ZIP Code Regex
100% Client-Side β€’ 0 B Data Leaves Browser
validation

United States Postal ZIP Code Regex

Matches 5-digit US ZIP codes and standard 9-digit ZIP+4 formats (12345 or 12345-6789).

Regular Expression Pattern:
/^\d{5}(?:-\d{4})?$/
Valid Match Example:
94016-1234
Invalid / Non-Match Example:
9401

Regex Syntax Breakdown & Explanation

  • β€’^\d{5} : Mandatory 5-digit base postal zone
  • β€’(?:-\d{4})?$ : Optional hyphen and 4-digit routing extension

Implementation in Popular Languages

JavaScript / TypeScript
const regex = /^\d{5}(?:-\d{4})?$/;
const isValid = regex.test("94016-1234");
console.log(isValid); // true
Python (re)
import re

pattern = r"^\d{5}(?:-\d{4})?$"
match = re.match(pattern, "94016-1234")
print(bool(match)) # True
Go (regexp)
package main
import (
  "fmt"
  "regexp"
)

func main() {
  re := regexp.MustCompile(`^\d{5}(?:-\d{4})?$`)
  fmt.Println(re.MatchString("94016-1234"))
}
Frequently Asked Questions

Frequently Asked Questions

Everything you need to know regarding specifications, syntax, and security best practices.

The regular expression pattern is /^\d{5}(?:-\d{4})?$/. Matches 5-digit US ZIP codes and standard 9-digit ZIP+4 formats (12345 or 12345-6789).