此页面仅提供英文版本,导航菜单保持你的语言。

Address basics · 6 min read

How to Validate an Address Without Guessing

A practical validation checklist: required fields, postal format, country rules, and the difference between format validation and delivery validation.

By Charlie Simmon ·

On this page
  1. Layer 1: required fields
  2. Layer 2: format rules
  3. Layer 3: delivery validation
  4. Questions

Address validation is not one check. A form can confirm that the fields are present, that the postal code matches the country pattern, and that the city and region are plausible. That is different from confirming that a carrier can deliver to the door.

Layer 1: required fields

Check that the street, city, country, and any required postal code are present. Make the error message name the field instead of saying “invalid address”.

Layer 2: format rules

Validate the postal code against the selected country, keep leading zeros, and allow the unit to be optional. Reject a US state code in a country that does not use state codes.

Layer 3: delivery validation

Only a postal or address-verification service can confirm delivery. It costs money and can still be wrong for new buildings. Do not pretend that a format check is a delivery guarantee.

Questions

Can I validate an address for free?+
You can validate the format for free. Delivery validation usually requires a paid service or the postal operator.
What should an error message say?+
Name the field and the expected format, for example “ZIP code must be five digits” rather than “invalid address”.

Examples are synthetic. Do not use a generated address for identity checks, account registration, or delivery.

Reference standards

Read next

All guides