What counts as valid

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.