What counts as valid
- Exactly five digits, such as
02108. Leading zeros are required for codes in the Northeast, Puerto Rico and the Virgin Islands. - Five digits, a hyphen and four digits, such as
02108-1234. A space instead of the hyphen is common on envelopes but is normalized by most systems. - Letters, fewer than five digits, or more than nine digits are never a valid U.S. ZIP.
Validation in your own code
The regular expression ^\d{5}(?:-\d{4})?$ matches both formats. Store ZIP codes as text, never as integers, and check existence against a maintained dataset or an address verification service rather than against the pattern alone. Our ZIP code lookup API guide covers the options.