Your ZIP code validation is probably wrong — not because you wrote bad code, but because a ZIP code is not a number. It is a string that happens to contain digits, and treating it as an integer is one of the most common ways address forms quietly lose data.
The leading-zero problem
ZIP codes in the northeastern United States frequently begin with 0: 02108 (Boston), 07030 (Hoboken), 08540 (Princeton). The moment one of these passes through parseInt, a spreadsheet import, or an INT() SQL column, the leading zero disappears. 02108 becomes 2108. The address is now wrong, and often undeliverable.
This is not a rare edge case. It is a large and populated part of the country.
Three places the bug hides
-
The form input.
type="number"on a ZIP field strips leading zeros and lets users enter exponents. Usetype="text"withinputmode="numeric". - The backend type. An integer column cannot represent 02108. Store ZIP codes as strings.
- The export. CSV opened in Excel will happily convert 02108 to 2108. Prefix with an apostrophe or quote the field, and be deliberate about how consumers read it.
A ZIP+4 code like 02108-1234 adds another wrinkle: the hyphen means it was never a number to begin with.
Test it with data that actually breaks
If every ZIP in your fixtures looks like 94105, none of this will ever surface. The fix is to generate test addresses that include leading-zero ZIPs, ZIP+4 formats, unit numbers and names with punctuation — and keep them as reproducible fixtures in your repo.
AddressLab is a free, no-sign-up generator that produces synthetic US address records including leading-zero ZIP prefixes, multi-country formats and tax-free state addresses. Save records locally and export selected fields as CSV or JSON, so your CI runs against the same awkward cases every time.
Generated addresses are for development, testing, education and prototypes. They are not real identities and will not receive mail.
The next time someone says "a ZIP is just a five-digit number", hand them 02108 and watch the assumptions fall apart.
Top comments (1)
02108 becoming 2108 is the perfect example — Boston is not an edge case, and the address silently becomes undeliverable rather than failing loudly. The export hiding place is the one I would have missed: the form and the database column are places you think to check, but a CSV opened in Excel quietly converting 02108 to 2108 happens after you think the bug is fixed. Your fixture point lands too — if every test ZIP looks like 94105, none of this ever surfaces. Which of the three hiding places have you seen bite a real team first, the form input, the integer column, or the Excel export?