Skip to content

Phone object

libphonenumber: com.google.i18n.phonenumbers.Phonenumber.PhoneNumber

NF.Phone holds the structured fields of a phone number. Obtain instances via NF.parse rather than constructing empty objects unless you build test data manually.

GetterTypeDescription
getCountryCode()IntegerCountry calling code (e.g. 1, 39, 41).
getNationalNumber()LongNational significant number without trunk prefix.
getExtension()StringExtension digits, if present.
getRawInput()StringOriginal input when parsed with NF.parseAndKeepRawInput.
getCountryCodeSource()NF.CountryCodeSourceHow the country code was inferred.
isItalianLeadingZero()BooleanItaly-specific leading-zero flag.
getNumberOfLeadingZeros()IntegerItaly-specific leading-zero count.
getPreferredDomesticCarrierCode()StringDomestic carrier code when set.

Each field has a matching has…() method (e.g. hasCountryCode()) indicating whether the field is set.

Fluent setters (setCountryCode, setNationalNumber, …) and clear…() methods exist for manual construction; typical subscriber code only reads fields after parsing.

NF.Phone.copy

Returns a deep copy of this phone number.

Signatures

global NF.Phone copy()

Parameters

None; instance method on NF.Phone.

Returns

New NF.Phone with the same field values.

Throws

None.

libphonenumber

PhoneNumber.Builder.clone / copy via mergeFrom

Example

NF.Phone original = NF.parse('+1 650-253-0000', 'US');
NF.Phone snapshot = original.copy();

NF.Phone.exactlySameAs

Returns whether two phone objects represent the same number fields.

Signatures

global Boolean exactlySameAs(NF.Phone other)

Parameters

NameTypeDescription
otherNF.PhonePhone to compare.

Returns

true if all set fields match.

Throws

None.

libphonenumber

PhoneNumber.exactlySameAs(PhoneNumber)

Example

Boolean same = phone.exactlySameAs(phone.copy()); // true

NF.Phone.clear

Clears all fields on this instance.

Signatures

global NF.Phone clear()

Parameters

None.

Returns

this for chaining.

Throws

None.

libphonenumber

PhoneNumber.clear()

Example

reusable.clear();
NF.parseInto(nextRawValue, 'US', reusable);