PhoneNumberResult

interface PhoneNumberResult extends FieldResult { valid: boolean; value?: string; error?: ValidationError<'blank' | 'invalid'>; country?: string; type?: 'premium_rate' | 'toll_free' | 'shared_cost' | 'voip' | 'personal_number' | 'pager' | 'uan' | 'voicemail' | 'fixed_line_or_mobile' | 'fixed_line' | 'mobile'; national?: string; international?: string; }

What POST /v1/validate answers for phone_number: the number read with libphonenumber, as typed in the address country, and how it is written.

The example is (415) 555-2671 typed on a US address.

Example

CODE
{
  "valid": true,
  "value": "+14155552671",
  "country": "US",
  "type": "fixed_line_or_mobile",
  "national": "(415) 555-2671",
  "international": "+1 415 555 2671"
}

Hierarchy


Properties

valid: boolean

Overrides valid

Whether the number is one its country has assigned. Never null: every number is read.

value: string

Overrides value

The number in E.164, +14155552671, where valid is true. A number that does not pass has none, and is sent as typed.

error: ValidationError<'blank' | 'invalid'>

Overrides error

Where valid is false: blank when no digit was typed, invalid otherwise.

country: string

Where valid is true, the ISO 3166-1 alpha-2 country the number belongs to, which need not be the address country: 011 44 7400 123456 typed on a US address is GB.

type: 'premium_rate' | 'toll_free' | 'shared_cost' | 'voip' | 'personal_number' | 'pager' | 'uan' | 'voicemail' | 'fixed_line_or_mobile' | 'fixed_line' | 'mobile'

Where valid is true, what kind of number it is: toll_free for (800) 555-0199, and fixed_line_or_mobile for (415) 555-2671, because US numbers do not say which. See PhoneNumberType.

national: string

Where valid is true, how the number's own country writes it at home: (415) 555-2671. An extension typed after it is kept: (415) 555-2671 ext. 12.

international: string

Where valid is true, how it is written to be dialled from abroad: +1 415 555 2671.