Skip to content

PhoneNumber

A parsed number, returned by parsePhoneNumber and by a controller’s getPhoneNumber. Thirteen methods query and format it. Every answer derives from the state resolved at parse time.

The examples share one number:

const number = parsePhoneNumber('+1 (415) 555-0132');

Whether the number exists in its region’s numbering plan.

number.isValid(); // true

Whether the number is valid for one region specifically. Mirrors libphonenumber’s isValidNumberForRegion.

number.isValidForRegion('US'); // true
number.isValidForRegion('CA'); // false

Whether the calling code resolves and the length is one the region dials. The digits themselves go unchecked, so a possible number can still be invalid.

number.isPossible(); // true
parsePhoneNumber('+1 123-456-7890').isPossible(); // true, ten digits is a US length

The possibility check as a PossibilityResult reason code, so a failed isPossible says why.

number.isPossibleWithReason(); // 'IS_POSSIBLE'
parsePhoneNumber('+1 415').isPossibleWithReason(); // 'TOO_SHORT'

The fault to correct, or null when none applies. One of the nine typed ValidationError variants.

number.getValidationError(); // null
parsePhoneNumber('+1 415').getValidationError(); // { kind: 'TOO_SHORT', minLength: 10 }

The six reason codes isPossibleWithReason returns. Mirrors libphonenumber’s ValidationResult.

Value Meaning
IS_POSSIBLE The calling code resolves and the length is dialled nationally
IS_POSSIBLE_LOCAL_ONLY The length is dialled only inside its own area
INVALID_CALLING_CODE The digits begin with no known calling code
TOO_SHORT Fewer digits than the region’s shortest number
TOO_LONG More digits than the region’s longest number
INVALID_LENGTH The length falls in a gap between valid lengths

The region the number resolves to, or null when none does.

number.getRegion(); // 'US'

The country calling code read from the digits, without the +, or null when there are none.

number.getCallingCode(); // '1'

The national significant number: digits only, with the national prefix stripped.

number.getNationalNumber(); // '4155550132'

The line type, such as MOBILE or FIXED_LINE. UNKNOWN when the number is not valid or the type is ambiguous. The full value list is NUMBER_TYPES.

number.getNumberType(); // 'FIXED_LINE_OR_MOBILE'
parsePhoneNumber('+1 800 234 5678').getNumberType(); // 'TOLL_FREE'

Each format method returns null when the number is not possible:

parsePhoneNumber('+1 415').formatE164(); // null
number.formatE164(); // '+14155550132'
number.formatNational(); // '(415) 555-0132'
number.formatInternational(); // '+1 415-555-0132'
number.formatRfc3966(); // 'tel:+1-415-555-0132'

Twelve of the thirteen methods have a libphonenumber counterpart, each compared with Google’s implementation on every corpus input. getValidationError is Telixon’s own surface, with no counterpart to compare. The numbers, the method, and the cadence are on Verified.