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');Validity
Section titled “Validity”isValid
Section titled “isValid”Whether the number exists in its region’s numbering plan.
number.isValid(); // trueisValidForRegion
Section titled “isValidForRegion”Whether the number is valid for one region specifically. Mirrors libphonenumber’s
isValidNumberForRegion.
number.isValidForRegion('US'); // truenumber.isValidForRegion('CA'); // falseisPossible
Section titled “isPossible”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(); // trueparsePhoneNumber('+1 123-456-7890').isPossible(); // true, ten digits is a US lengthisPossibleWithReason
Section titled “isPossibleWithReason”The possibility check as a PossibilityResult reason code, so a failed
isPossible says why.
number.isPossibleWithReason(); // 'IS_POSSIBLE'parsePhoneNumber('+1 415').isPossibleWithReason(); // 'TOO_SHORT'getValidationError
Section titled “getValidationError”The fault to correct, or null when none applies. One of the nine typed
ValidationError variants.
number.getValidationError(); // nullparsePhoneNumber('+1 415').getValidationError(); // { kind: 'TOO_SHORT', minLength: 10 }PossibilityResult
Section titled “PossibilityResult”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 |
Identity
Section titled “Identity”getRegion
Section titled “getRegion”The region the number resolves to, or null when none does.
number.getRegion(); // 'US'getCallingCode
Section titled “getCallingCode”The country calling code read from the digits, without the +, or null when there are none.
number.getCallingCode(); // '1'getNationalNumber
Section titled “getNationalNumber”The national significant number: digits only, with the national prefix stripped.
number.getNationalNumber(); // '4155550132'getNumberType
Section titled “getNumberType”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'Formats
Section titled “Formats”Each format method returns null when the number is not possible:
parsePhoneNumber('+1 415').formatE164(); // nullformatE164
Section titled “formatE164”number.formatE164(); // '+14155550132'formatNational
Section titled “formatNational”number.formatNational(); // '(415) 555-0132'formatInternational
Section titled “formatInternational”number.formatInternational(); // '+1 415-555-0132'formatRfc3966
Section titled “formatRfc3966”number.formatRfc3966(); // 'tel:+1-415-555-0132'Conformance
Section titled “Conformance”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.