ValidateResponse

interface ValidateResponse { lang: Lang; fields: { phone_number?: PhoneNumberResult; postcode?: PostcodeResult; [field: string]: FieldResult | undefined }; }

The response of POST /v1/validate: an answer for each field sent, keyed as sent. A field that does not pass is still a 200; a 400 is a body that cannot be read. A field the route does not check, state among them, is answered { "valid": null }.

The example is the answer to the ValidateRequest example, sent with ?lang=en: the phone number passes, and 10001 is a US ZIP Code, but New York's, not California's.

Example

CODE
{
  "lang": "en",
  "fields": {
    "phone_number": {
      "valid": true,
      "value": "+14155552671",
      "country": "US",
      "type": "fixed_line_or_mobile",
      "national": "(415) 555-2671",
      "international": "+1 415 555 2671"
    },
    "postcode": {
      "valid": false,
      "error": {
        "code": "not_in_state",
        "message": "Enter a valid ZIP Code for California"
      },
      "state": "NY"
    },
    "state": { "valid": null }
  }
}

Properties

lang: Lang

The language every message is in: ?lang=, else the first language of the browser's Accept-Language the API serves, else English. content-language says the same.

fields: { phone_number?: PhoneNumberResult; postcode?: PostcodeResult; [field: string]: FieldResult | undefined }

A PhoneNumberResult for phone_number, a PostcodeResult for postcode, and a FieldResult for any other field.

Properties