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.
Core fields
Section titled “Core fields”| Getter | Type | Description |
|---|---|---|
getCountryCode() | Integer | Country calling code (e.g. 1, 39, 41). |
getNationalNumber() | Long | National significant number without trunk prefix. |
getExtension() | String | Extension digits, if present. |
getRawInput() | String | Original input when parsed with NF.parseAndKeepRawInput. |
getCountryCodeSource() | NF.CountryCodeSource | How the country code was inferred. |
isItalianLeadingZero() | Boolean | Italy-specific leading-zero flag. |
getNumberOfLeadingZeros() | Integer | Italy-specific leading-zero count. |
getPreferredDomesticCarrierCode() | String | Domestic 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
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
| Name | Type | Description |
|---|---|---|
other | NF.Phone | Phone to compare. |
Returns
true if all set fields match.
Throws
None.
libphonenumber
PhoneNumber.exactlySameAs(PhoneNumber)
Example
Boolean same = phone.exactlySameAs(phone.copy()); // trueNF.Phone.clear
Clears all fields on this instance.
Signatures
global NF.Phone clear()Parameters
Returns
this for chaining.
Throws
None.
libphonenumber
PhoneNumber.clear()
Example
reusable.clear();NF.parseInto(nextRawValue, 'US', reusable);