Skip to main content
AllDevToolsHub
Back to all patterns

US ZIP Code Validation

Validation

Validates US ZIP codes in 5-digit (12345) and ZIP+4 (12345-6789) formats.

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

How it works

US ZIP codes are 5 digits. The ZIP+4 extension adds a hyphen and 4 more digits for more precise delivery routing. This pattern accepts both formats.

Test Cases

Should Match

  • 90210
  • 10001-1234
  • 00501

Should NOT Match

  • 1234
  • 123456
  • ABCDE

Quick Summary

Validates US ZIP codes in 5-digit (12345) and ZIP+4 (12345-6789) formats. Does not validate whether the ZIP code is actually assigned, use a ZIP code database for that.

Key Takeaways

Key Takeaways

  • 5-digit ZIP: required; ZIP+4 extension: optional
  • Leading zeros are valid (e.g., 00501 for Adjuntas, Puerto Rico)
  • Does not validate geographic assignment, 00000 passes but is not a real ZIP
  • For international postal codes, use country-specific patterns
Use Cases

When to use it

  • Validating address forms in US e-commerce applications
  • Filtering shipping address inputs
  • Parsing address data from CSV imports
Watch out

Common Mistakes

  • Treating ZIP codes as numbers, leading zeros are significant (store as string)
  • Using this for Canadian postal codes, Canada uses A1A 1A1 format
FAQ

US ZIP Code Validation, Frequently Asked

How do I validate Canadian postal codes?

Canadian postal codes follow the pattern A1A 1A1: ^[A-Z]\d[A-Z] \d[A-Z]\d$ (case-insensitive).

How do I validate UK postcodes?

UK postcodes are complex. Use the official Royal Mail regex or a dedicated library.