HTML patterns for US phone numbers and ZIP codes: inputs, failures and limits
Use explicit US-only phone and ZIP formats, preserve leading zeroes, and test empty values, separators and rejected inputs before publishing your form.
These examples check formatting only. A match does not establish that a phone number is assigned or that an address is deliverable. Do not use these US-only patterns for an international audience.
Start with visible instructions and the right input type
Use tel for the phone field and text for the ZIP field. A ZIP code is an identifier, not a quantity: a number input can discard leading zeroes and does not support the pattern constraint. Add a visible format hint, not just a placeholder that disappears while typing.
The phone pattern below accepts ten digits with optional paired parentheses and common separators. It deliberately rejects +1 and extensions. If those are valid for your users, change the documented requirement and retest instead of silently stripping their input.
<label for="phone">US phone number (10 digits, required)</label>
<input id="phone" name="phone" type="tel" autocomplete="tel-national"
pattern="(?:\(\d{3}\)|\d{3})[\x2d. ]?\d{3}[\x2d. ]?\d{4}" required aria-describedby="phone-help">
<p id="phone-help">For example: (415) 555-0132. US numbers only.</p>
<label for="zip">US ZIP code (required)</label>
<input id="zip" name="zip" type="text" autocomplete="postal-code"
pattern="\d{5}(?:\x2d\d{4})?" required aria-describedby="zip-help">
<p id="zip-help">Five digits, optionally followed by a hyphen and four digits.</p>Run this phone-number test matrix
Use the validation-pattern generator with the US phone number preset. Try the values below and check the result. The generator tests format; in your actual form, required also determines whether an empty field is allowed.
| Input | Expected in required field | Why |
|---|---|---|
| (415) 555-0132 | Accept | Paired parentheses and ten digits |
| 4155550132 | Accept | Ten digits without separators |
| 415.555.0132 | Accept | Dot separators |
| (4155550132 | Reject | Unpaired opening parenthesis |
| 415)5550132 | Reject | Unpaired closing parenthesis |
| +1 415-555-0132 | Reject | Country prefix is outside this stated format |
| 415-555-0132 ext 9 | Reject | Extensions are outside this stated format |
| Empty string | Reject | The field is required |
Preserve leading zeroes in ZIP codes
The ZIP pattern accepts five digits and an optional four-digit extension separated by a hyphen. It does not check a postal database. Keep the value as text in storage and exports so that 02108 does not become 2108.
| Input | Expected | Reason |
|---|---|---|
| 02108 | Accept | Leading zero preserved |
| 94107-1234 | Accept | ZIP+4 format |
| 941071234 | Reject | Extension separator missing |
| 9410 | Reject | Too short |
| 94107 | Reject | Trailing space is not part of this pattern |
Check the native browser form, not only the regex
HTML pattern matches the entire non-empty value and uses Unicode-aware regular expression rules. Do not add JavaScript slash delimiters to the attribute. An empty optional input is allowed; required makes an empty answer invalid.
Submit a staging form with each test value and inspect the visible error experience using keyboard navigation and a narrow screen. An invalid pattern may fail to apply, and JavaScript submission can bypass native checks. Enforce the same business requirements on the server; browser validation is a convenience for visitors, not a security boundary.
Avoid sending a phone number, address or typed test value to analytics. Track only the preset, whether input was a sample or entered by the visitor, and a match/no-match outcome. A successful validation check is more informative than making a visitor spend longer on the page.