Skip to content

Interface: Phone

The Phone class represents a phone number and provides methods to retrieve information about it. It implements the PhoneModel interface.

Implements

Implements

  • PhoneModel

Properties

PropertyModifierTypeDescription
countryreadonlyCountryOrUnknownReturns the country code of the phone number.
e164readonlystringReturns the E.164 format of the phone number. Remarks If the phone number is not a valid phone number, the initial phone number which was passed to the constructor is returned.
internationalreadonlystringReturns the international format of the phone number. Remarks If the phone number is not a valid phone number, the initial phone number which was passed to the constructor is returned.
mobilereadonlybooleanReturns whether the phone number is a mobile number or not.
nationalreadonlystringReturns the national format of the phone number. Remarks If the phone number is not a valid phone number, the initial phone number which was passed to the constructor is returned.
phonereadonlystringReturns the phone number as a string stripped of all non-numeric characters.
rawreadonlystringReturns the raw phone number. Remarks If the phone number is not a valid phone number, the initial phone number which was passed to the constructor is returned.
timezonereadonlyPossiblePhoneTimezoneReturns the timezone of the phone number.
typereadonly| "FIXED_LINE" | "MOBILE" | "FIXED_LINE_OR_MOBILE" | "TOLL_FREE" | "PREMIUM_RATE" | "SHARED_COST" | "VOIP" | "PERSONAL_NUMBER" | "PAGER" | "UAN" | "VOICEMAIL" | "UNKNOWN" | "INVALID"Returns the type of the phone number.
validreadonlybooleanReturns whether the phone number uses a valid format for the parsed country or not.

Methods

inspect()

ts
inspect(): string;

Returns a stringified representation of the phone number.

Returns

string

  • A string representation of the phone number.

serialize()

ts
serialize(): string;

Serializes the phone object to an obfuscated string which can be used to recreate the phone object from the Phone.deserialize method.

Returns

string

  • The serialized phone object.

toJSON()

ts
toJSON(): {
  country: CountryOrUnknown;
  e164: string;
  international: string;
  mobile: boolean;
  national: string;
  phone: string;
  raw: string;
  timezone: PossiblePhoneTimezone;
  type:   | "FIXED_LINE"
     | "MOBILE"
     | "FIXED_LINE_OR_MOBILE"
     | "TOLL_FREE"
     | "PREMIUM_RATE"
     | "SHARED_COST"
     | "VOIP"
     | "PERSONAL_NUMBER"
     | "PAGER"
     | "UAN"
     | "VOICEMAIL"
     | "UNKNOWN"
     | "INVALID";
  valid: boolean;
};

Returns a JSON representation of the phone number.

Returns

  • A JSON-safe representation of the phone number.
NameTypeDescription
countryCountryOrUnknownThe country code of the phone number. Remarks In cases where the country was not recognized and could not be guessed from the phone number, 'XX' is used.
e164stringThe phone number as a string in the E.164 format.
internationalstringThe phone number as a string in the international format for the parsed country.
mobilebooleanWhether the phone number is possibly a mobile number or not.
nationalstringThe phone number as a string in the national format for the parsed country.
phonestringThe phone number as a string stripped of all non-numeric characters.
rawstringThe phone number as a string stripped of all non-numeric characters.
timezonePossiblePhoneTimezoneThe estimated timezone of the phone number based on the phone number's country. It can be either a CountryTimezone or 'UTC'.
type| "FIXED_LINE" | "MOBILE" | "FIXED_LINE_OR_MOBILE" | "TOLL_FREE" | "PREMIUM_RATE" | "SHARED_COST" | "VOIP" | "PERSONAL_NUMBER" | "PAGER" | "UAN" | "VOICEMAIL" | "UNKNOWN" | "INVALID"The type of the phone number.
validbooleanWhether the phone number uses a valid format for the parsed country or not.

Implementation of

ts
PhoneModel.toJSON;

toObject()

ts
toObject(): {
  country: CountryOrUnknown;
  e164: string;
  international: string;
  mobile: boolean;
  national: string;
  phone: string;
  raw: string;
  timezone: PossiblePhoneTimezone;
  type:   | "FIXED_LINE"
     | "MOBILE"
     | "FIXED_LINE_OR_MOBILE"
     | "TOLL_FREE"
     | "PREMIUM_RATE"
     | "SHARED_COST"
     | "VOIP"
     | "PERSONAL_NUMBER"
     | "PAGER"
     | "UAN"
     | "VOICEMAIL"
     | "UNKNOWN"
     | "INVALID";
  valid: boolean;
};

Returns an object representation of the phone number.

Returns

  • An object representation of the phone number.
NameTypeDescription
countryCountryOrUnknownThe country code of the phone number. Remarks In cases where the country was not recognized and could not be guessed from the phone number, 'XX' is used.
e164stringThe phone number as a string in the E.164 format.
internationalstringThe phone number as a string in the international format for the parsed country.
mobilebooleanWhether the phone number is possibly a mobile number or not.
nationalstringThe phone number as a string in the national format for the parsed country.
phonestringThe phone number as a string stripped of all non-numeric characters.
rawstringThe phone number as a string stripped of all non-numeric characters.
timezonePossiblePhoneTimezoneThe estimated timezone of the phone number based on the phone number's country. It can be either a CountryTimezone or 'UTC'.
type| "FIXED_LINE" | "MOBILE" | "FIXED_LINE_OR_MOBILE" | "TOLL_FREE" | "PREMIUM_RATE" | "SHARED_COST" | "VOIP" | "PERSONAL_NUMBER" | "PAGER" | "UAN" | "VOICEMAIL" | "UNKNOWN" | "INVALID"The type of the phone number.
validbooleanWhether the phone number uses a valid format for the parsed country or not.

Implementation of

ts
PhoneModel.toObject;

toString()

ts
toString(): string;

Returns the E.164 format of the phone number as a string.

Returns

string

  • The E.164 format of the phone number.

Implementation of

ts
PhoneModel.toString;