ZIP code and postcode input
The right field depends on which countries you serve. Getting it wrong blocks people at checkout.
US only, 5 digits
<label for="zip">ZIP code</label>
<input id="zip" name="zip" type="text" inputmode="numeric"
pattern="[0-9]{5}" maxlength="5" autocomplete="postal-code">
Never type="number": ZIP codes in New England start with 0, and a number field turns 02134 into 2134.
US with ZIP+4
ZIP+4 needs a hyphen: 02134-1234. The iPhone number pad has no hyphen key. Either use type="text" with the standard keyboard, or accept 9 digits without the hyphen and add it yourself.
UK, Canada and most other countries
UK postcodes (SW1A 1AA) and Canadian postal codes (K1A 0B1) mix letters, digits and a space. Use type="text", autocomplete="postal-code" and autocapitalize="characters" so letters come out in capitals. Do not use a number pad: these codes cannot be typed on it.
International forms
If the country is chosen first, switch the field's inputmode after the choice: numeric for the US and Germany, text for the UK, Canada and the Netherlands. If you cannot, use the standard keyboard for everyone; a slower keyboard is better than a blocked one.
Validate gently
Trim spaces, accept lower case and upper-case it yourself, and only check the format the chosen country uses. Explain errors next to the field ("UK postcodes look like SW1A 1AA").
Frequently asked questions
Why does my ZIP code field lose the first 0?
It is type="number". Change it to type="text" inputmode="numeric".
Which autocomplete token is right for ZIP code?
postal-code. "zip" is not a valid token and is ignored.
Found a mistake or want a check added? Write to contact (at) mobileformcheck.com.