Regex for US ZIP Codes, States, Phone Numbers and Addresses: What Works and What Cannot

Published November 15, 2026 by the USA Address Generator editorial team · Form Validation · 8 min read

Tested patterns for ZIP, ZIP+4, state codes and NANP phone numbers, plus an honest account of why no regular expression can validate a street address and what to do instead.


Regular expressions are good at checking that a value has the right shape and bad at checking that it is real. For US address data that draws a clear line: ZIP codes, state codes and phone numbers have a fixed shape and can be checked well; street addresses do not, and every pattern that tries rejects valid addresses. Here are patterns that hold up, the cases each one misses, and where to stop.

ZIP code

const ZIP = /^\d{5}(?:-\d{4})?$/;

ZIP.test('90210');        // true
ZIP.test('02134');        // true
ZIP.test('90210-3456');   // true
ZIP.test('9021');         // false
ZIP.test('90210-34');     // false

Five digits, optionally followed by a hyphen and four more. That is the whole format.

People also type nine digits with no hyphen, or with a space. Rather than writing a looser validation pattern, normalise first and validate after:

function normaliseZip(input) {
  const digits = input.replace(/[^\d]/g, '');
  if (digits.length === 5) return digits;
  if (digits.length === 9) return `${digits.slice(0, 5)}-${digits.slice(5)}`;
  return null; // not a ZIP
}

What the pattern cannot tell you: whether the ZIP exists. 00000 and 99999 both match and neither is in use. Whether it belongs to the selected state is also beyond a pattern; that needs a lookup table, and a small number of ZIP codes cross state lines. The ZIP prefix lookup shows which three-digit prefixes belong to which state.

Two implementation notes. Use inputmode="numeric" on a text input, never type="number", or the browser will strip leading zeros. And in languages where \d matches any Unicode digit, write [0-9] instead, so that digits from other scripts are not accepted.

State code

A state code is two letters, but ^[A-Z]{2}$ accepts XX and ZZ. The set is small and fixed, so list it:

const STATE = new RegExp(
  '^(?:A[KLRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|' +
  'N[CDEHJMVY]|O[HKR]|PA|RI|S[CD]|T[NX]|UT|V[AT]|W[AIVY]|' +   // 50 states + DC
  'AS|GU|MP|PR|VI|' +                                           // territories
  'AA|AE|AP)$'                                                  // military
);

In practice a Set is clearer than a regex for this, and easier to keep correct:

const STATES = new Set(['AL', 'AK', 'AZ', /* ... */ 'WY', 'DC', 'PR', 'VI', 'GU', 'AS', 'MP', 'AA', 'AE', 'AP']);
const isState = (value) => STATES.has(value.trim().toUpperCase());

Whichever form you use, the important part is the last two lines of the list. A state check with fifty entries rejects the District of Columbia, every territory and every military address.

Phone number

US numbers follow the North American Numbering Plan: a three-digit area code, a three-digit exchange and a four-digit line number. Neither the area code nor the exchange can begin with 0 or 1.

const PHONE = /^(?:\+?1[-. ]?)?\(?([2-9]\d{2})\)?[-. ]?([2-9]\d{2})[-. ]?(\d{4})$/;

PHONE.test('(212) 555-0142');    // true
PHONE.test('212-555-0142');      // true
PHONE.test('+1 212 555 0142');   // true
PHONE.test('2125550142');        // true
PHONE.test('112-555-0142');      // false: area code starts with 1
PHONE.test('212-155-0142');      // false: exchange starts with 1

As with ZIP codes, the more robust approach is to strip formatting, check the digits, and store one canonical form:

function normalisePhone(input) {
  let digits = input.replace(/\D/g, '');
  if (digits.length === 11 && digits.startsWith('1')) digits = digits.slice(1);
  if (!/^[2-9]\d{2}[2-9]\d{6}$/.test(digits)) return null;
  return `+1${digits}`; // E.164
}

What it cannot tell you: whether the area code is assigned, whether the number is in service, or whether it is a mobile or a landline. It also does not handle extensions, which are common for business numbers; if you need them, collect the extension in its own field.

For test data, the numbers 555-0100 through 555-0199 are reserved for fictional use in every area code, so they will never ring a real subscriber. The phone number generator produces numbers in that range, and the guide to the North American Numbering Plan explains the structure in more detail.

PO Box detection

Sometimes the aim is not to validate but to recognise a type of address, most often a PO Box that a carrier cannot deliver to.

const PO_BOX = /\b(?:p\.?\s*o\.?\s*|post\s+office\s+)box\b/i;

This catches PO Box, P.O. Box, P O Box and Post Office Box. It is suitable for showing a warning. It is not suitable for blocking an order, because it has false positives and false negatives; the article on PO Boxes and private mailboxes explains why.

Street address: why there is no good pattern

The pattern most often copied for a street line is some version of "a number, then words, then a suffix":

// Do not use this
const STREET = /^\d+\s+[A-Za-z0-9\s]+\s(?:St|Ave|Rd|Blvd|Dr|Ln|Ct)\.?$/i;

Every one of the following is a valid US delivery line, and that pattern rejects all of them:

Address lineWhy it fails
150 BROADWAYNo suffix
123-45 67TH AVEHyphen in the house number
123 1/2 MAIN STFraction
N6W23001 BLUEMOUND RDStarts with a letter
842 E 1700 SEnds with a directional, not a suffix
PO BOX 1234No house number
RR 2 BOX 152Rural route
500 OAK ST APT 2Unit after the suffix
1200 PLACITA DEL SOLSuffix not in the list

You can keep adding alternatives, and the pattern becomes unreadable long before it becomes correct. USPS recognises several hundred suffix spellings, and the house number, the street name and the unit can each contain letters, digits, hyphens, slashes and spaces. A pattern loose enough to accept all real addresses accepts almost any string, and one tight enough to be meaningful turns customers away.

What to check instead

For the street line, check only what is truly universal:

function looksLikeDeliveryLine(input) {
  const value = input.trim();
  return value.length >= 3
      && value.length <= 100
      && /[A-Za-z0-9]/.test(value)             // not just punctuation
      && !/[<>{}\[\]\\^~`|]/.test(value);       // characters that never belong
}

Then spend the strictness where it works: a required city, a state from the full list, a ZIP that matches the pattern, and a ZIP whose prefix agrees with the state. Those four checks catch most typing mistakes. If you need to know that the address actually exists, that is a job for an address verification service that compares it with USPS delivery data, not for a pattern.

Testing the patterns

Patterns fail at the edges, so test them with a list rather than one or two examples. Keep a table of inputs that must pass and inputs that must fail, and run it on every change. The edge case checklist is a ready-made list of values that must pass. The address format validator shows the same shape checks applied to a whole address, and bulk output from the address generator is a quick way to confirm that a pattern does not reject ordinary records.