ZIP code and postcode input

The right field depends on which countries you serve. Getting it wrong blocks people at checkout.

Last updated November 30, 2026 · Keyboards checked on real phones: iPhone (iOS 17 and 18), Galaxy S24 and S25, Pixel 9, Motorola Edge 50 Fusion

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").

Postcode formats at a glance

CountryExampleBest keyboard
United States02134 or 02134-1234numeric for 5 digits; standard for ZIP+4 on iPhone
CanadaK1A 0B1standard, capitals
United KingdomSW1A 1AAstandard, capitals
Germany, France, Spain, Italy10115numeric
Netherlands1012 ABstandard, capitals
Japan100-0001standard (needs the hyphen on iPhone)
Australia2000numeric

ZIP+4 on real phones

We checked the number pads on real phones. With inputmode="numeric", a Galaxy has a ".-" key and Gboard on Pixel and Motorola has a dash, so people can type 02134-1234 there. The iPhone number pad has no dash at all. If you require the hyphen, iPhone users cannot finish the form. The safe approach is to accept 5 or 9 digits with or without the hyphen and format it yourself.

function cleanZip(raw) {
  const d = raw.replace(/\D/g, '');
  if (d.length === 5) return d;
  if (d.length === 9) return d.slice(0, 5) + '-' + d.slice(5);
  return null; // show an error next to the field
}
cleanZip('02134')      // "02134"
cleanZip('021341234')  // "02134-1234"
cleanZip('02134 1234') // "02134-1234"

Do you need the ZIP code at all?

Many checkouts ask for a ZIP code only to fill the city and state. If you look those up from the ZIP code, put the ZIP field first and fill the rest for people. If you only need the country for tax or shipping, ask for that instead. Every field you remove is one fewer chance for a phone keyboard to get in the way.

Error messages that help

Show the message next to the field, in words, with an example of the right format: "Enter a 5-digit ZIP code, like 02134". Do not clear what was typed. If the ZIP code does not match the chosen state, say both values back ("ZIP code 02134 is in Massachusetts, not New York") so the person can tell which one is wrong. Check on submit or when the person leaves the field, not on every keystroke, because a half-typed ZIP code is not an error yet.

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.

Can people type ZIP+4 on the iPhone number pad?

No. It has no hyphen. Accept nine digits without one, or use the standard keyboard.

Found a mistake or want a check added? Write to contact (at) mobileformcheck.com.