PostcodeResult
interface PostcodeResult extends FieldResult {
valid: boolean | null;
value?: string;
error?: ValidationError<'blank' | 'invalid' | 'not_in_state'>;
state?: string;
}What POST /v1/validate answers for postcode: whether the country takes it, and, with a state sent beside it, whether that state does.
The examples are the US ZIP Code 10001 sent with state: "CA", and then on its own.
Example
{
"valid": false,
"error": { "code": "not_in_state", "message": "Enter a valid ZIP Code for California" },
"state": "NY"
}{ "valid": true, "value": "10001", "state": "NY" }Hierarchy
FieldResultPostcodeResult
Properties
valid: boolean | null
Overrides valid
Whether the postcode is one the country takes, and the state's where a state was sent. null where nothing can be checked: a country with no postcode pattern (one on the default layout, or one that collects no postcode), or a request with no country.
value: string
Overrides value
The postcode as its country writes it, 94103-1234 for 941031234, where valid is true.
error: ValidationError<'blank' | 'invalid' | 'not_in_state'>
Overrides error
Where valid is false: blank when nothing but separators was typed, invalid when it is not the country's format, and not_in_state when the country takes it but the state sent beside it does not. The not_in_state message names the state sent.
state: string
The state the postcode is in, as the code a form submits: NY for 10001. Only where one state's postcodes start the way it does, and beside not_in_state too, so a form can offer that state instead.