US ZIP Code & ZIP+4 Validation Testing: Leading Zeros, Tax Boundaries & Tax-Free State Traps
Reliable US address QA goes well beyond checking five digits. Production checkouts break on four recurring traps: numeric fields stripping leading zeros (02108, 03101, 00901), maxlength="5" rejecting valid ZIP+4 codes (19801-3012), 5-digit ZIPs crossing sales-tax district lines, and local municipal taxes inside Alaska and Montana despite 0% state tax.
1. Five-Digit ZIP vs. ZIP+4 Input and Normalization Traps
USPS Publication 28 defines both standard 5-digit ZIP codes (e.g., 19801) and 9-digit ZIP+4 codes (19801-3012), where the 4-digit add-on narrows mail sorting to a specific block face, building, or PO Box group. Browser autofill, Apple Pay, and enterprise ERP systems routinely paste full ZIP+4 strings.
Checkout forms break whenever a developer sets maxlength="5" (silently truncating or blocking autofill), uses <input type="number"> (stripping the leading zero from Boston 02108 or Manchester 03101), or forgets Puerto Rico (006xx–009xx) and the US Virgin Islands (008xx), which start with two zeros.
export function normalizeUsZip(raw) {
const cleaned = String(raw ?? '').trim().replace(/[\u2010-\u2015\s]+/g, '');
if (/^\d{9}$/.test(cleaned)) {
return `${cleaned.slice(0, 5)}-${cleaned.slice(5)}`;
}
return cleaned;
}
export const US_ZIP_RE = /^\d{5}(?:-\d{4})?$/;
// Valid: "02108", "03101", "00901", "19801-3012"
// Invalid: "2108" (stripped zero), "19801-" (dangling hyphen) 2. Why a 5-Digit ZIP Code Does Not Equal a Sales-Tax Jurisdiction
A frequent e-commerce defect is assuming every 5-digit ZIP maps 1-to-1 to a single combined sales-tax rate. USPS assigns ZIP codes strictly for postal carrier routing; they cross county lines, city incorporation boundaries, and special transit or stadium taxing districts all across the United States.
Two houses sharing one 5-digit ZIP can sit on opposite sides of a city limit with a 1%–3% difference in local tax. That is why production tax engines (Stripe Tax, Avalara AvaTax, Vertex, TaxJar) rely on street-level geocoding and ZIP+4 boundaries—and why QA suites should always pass full street, city, state, and ZIP+4 fields rather than testing rate tables by 5-digit ZIP alone.
3. Tax-Free State Rules: Avoiding False CI Failures on AK and MT
QA teams commonly pick one of the five "NOMAD" states (DE, OR, NH, MT, AK) to assert tax === 0.00 at checkout. While all five levy 0% statewide sales tax, only Delaware (DE), Oregon (OR), and New Hampshire (NH) also have 0% general local sales tax.
Alaska allows over 100 local boroughs and municipalities to levy municipal sales tax (Juneau 99801 is taxed, whereas Anchorage 99501 is 0%). Montana allows designated resort municipalities (such as Big Sky or Whitefish) to collect ~3–4% local resort tax. Also remember US economic nexus is destination-based: changing the card billing ZIP to Delaware does not waive sales tax on physical goods shipped to California or New York.
| QA Test Vector | Sample ZIP / ZIP+4 | What Bug It Catches |
|---|---|---|
| Pure 0% baseline (DE / OR) | 19801-3012 / 97204-2104 | Strict 0.00 tax assertion + ZIP+4 acceptance |
| 0% tax + leading zero (NH) | 03101 / 03101-1602 | 0% tax AND string preservation (03101 != 3101) |
| Double leading zero (PR) | 00901 | Detects integer casting & 3-digit truncation (901) |
| 0% state w/ local tax (AK) | 99501 vs 99801 | Verifies borough-level tax lookup (Anchorage 0% vs Juneau >0%) |
| Destination vs billing pair | DE billing + CA 94105 ship | Confirms ship-to sourcing overrides tax-free billing ZIP |
4. Three Separate Layers: Syntax, Assigned ZIP, and USPS DPV
Passing /^\d{5}(?:-\d{4})?$/ only proves formatting syntax—strings like 00000 or 99999 match the regex yet are unassigned. The second layer verifies that the 5-digit ZIP actually maps to the chosen US state and city (which synthetic specimens from AddressBench satisfy deterministically across all 51 jurisdictions).
The third layer—USPS CASS/DPV (Delivery Point Validation)—confirms whether a physical mailbox exists at a specific house number. Synthetic QA fixtures are intentionally not DPV-deliverable so real residents are never impacted; switch to your carrier or tax vendor official sandbox vectors whenever you specifically test physical deliverability scoring.