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
- You can validate the format for free. Delivery validation usually requires a paid service or the postal operator.
- Name the field and the expected format, for example “ZIP code must be five digits” rather than “invalid address”.
Can I validate an address for free?+
What should an error message say?+
Examples are synthetic. Do not use a generated address for identity checks, account registration, or delivery.