Metadata
Regional metadata describes how numbers are validated and formatted in each country. Load objects with the static methods below, then read fields through the accessors in Reading metadata. You do not construct metadata yourself.
libphonenumber: com.google.i18n.phonenumbers.Phonemetadata.PhoneMetadata, PhoneNumberDesc, NumberFormat
Loading metadata
Section titled “Loading metadata”NF.metadataForRegion
Returns metadata for a geographical region (ISO 3166-1 alpha-2).
Signatures
global static NF.Metadata metadataForRegion(String regionCode)Parameters
| Name | Type | Description |
|---|---|---|
regionCode | String | Region code (e.g. US, IT). Unknown regions such as ZZ return null. |
Returns
NF.Metadata for the region, or null when no metadata exists.
Throws
None.
libphonenumber
PhoneNumberUtil.getMetadataForRegion(String) (via metadata index)
Example
NF.Metadata meta = NF.metadataForRegion('IT');if (meta != null && meta.hasNationalPrefix()) { String trunk = meta.getNationalPrefix(); // e.g. "0"}NF.metadataForNonGeographicalRegion
Returns metadata for a non-geographical entity (toll-free, shared-cost ranges, etc.).
Signatures
global static NF.Metadata metadataForNonGeographicalRegion(Integer countryCallingCode)Parameters
| Name | Type | Description |
|---|---|---|
countryCallingCode | Integer | Calling code for the non-geo entity (e.g. 800, 808). |
Returns
NF.Metadata, or null if the calling code is unknown or 0.
Throws
None.
libphonenumber
PhoneNumberUtil.getMetadataForNonGeographicalRegion(int) (via metadata index)
Example
NF.Metadata tollFreeMeta = NF.metadataForNonGeographicalRegion(800);if (tollFreeMeta != null) { Integer cc = tollFreeMeta.getCountryCode(); // 800}Reading metadata
Section titled “Reading metadata”Objects returned by NF.metadataForRegion and NF.metadataForNonGeographicalRegion are for inspection only. Builder and mutation methods (set*, add*, clear*) are not part of the public reference.
NF.Metadata
Section titled “NF.Metadata”Line-type descriptors
Section titled “Line-type descriptors”Each line type is an optional NF.PhoneDesc. Call has…() before get…().
| has / get | libphonenumber field |
|---|---|
hasGeneralDesc / getGeneralDesc | general_desc |
hasFixedLine / getFixedLine | fixed_line |
hasMobile / getMobile | mobile |
hasTollFree / getTollFree | toll_free |
hasPremiumRate / getPremiumRate | premium_rate |
hasSharedCost / getSharedCost | shared_cost |
hasVoip / getVoip | voip |
hasPersonalNumber / getPersonalNumber | personal_number |
hasPager / getPager | pager |
hasUan / getUan | uan |
hasVoicemail / getVoicemail | voicemail |
hasNoInternationalDialling / getNoInternationalDialling | no_international_dialling |
Region identity and prefixes
Section titled “Region identity and prefixes”| Accessor | Type | libphonenumber |
|---|---|---|
hasId / getId | String | id |
hasCountryCode / getCountryCode | Integer | country_code |
hasInternationalPrefix / getInternationalPrefix | String | international_prefix |
hasPreferredInternationalPrefix / getPreferredInternationalPrefix | String | preferred_international_prefix |
hasNationalPrefix / getNationalPrefix | String | national_prefix |
hasPreferredExtnPrefix / getPreferredExtnPrefix | String | preferred_extn_prefix |
hasNationalPrefixForParsing / getNationalPrefixForParsing | String | national_prefix_for_parsing |
hasNationalPrefixTransformRule / getNationalPrefixTransformRule | String | national_prefix_transform_rule |
hasLeadingDigits / getLeadingDigits | String | leading_digits |
| Accessor | Type | libphonenumber |
|---|---|---|
hasSameMobileAndFixedLinePattern / getSameMobileAndFixedLinePattern | Boolean | same_mobile_and_fixed_line_pattern |
hasMainCountryForCode / getMainCountryForCode / isMainCountryForCode | Boolean | main_country_for_code |
hasMobileNumberPortableRegion / getMobileNumberPortableRegion / isMobileNumberPortableRegion | Boolean | mobile_number_portable_region |
Format rules
Section titled “Format rules”National and international format templates are indexed lists of NF.NumberFormatRule.
| Accessor | Returns | libphonenumber |
|---|---|---|
getNumberFormatCount | Integer | number_format count |
getNumberFormat(Integer index) | NF.NumberFormatRule | number_format(index) |
numberFormats() | List<NF.NumberFormatRule> | number_format list |
getIntlNumberFormatCount | Integer | intl_number_format count |
getIntlNumberFormat(Integer index) | NF.NumberFormatRule | intl_number_format(index) |
intlNumberFormats() | List<NF.NumberFormatRule> | intl_number_format list |
NF.Metadata us = NF.metadataForRegion('US');if (us != null && us.hasMobile()) { NF.PhoneDesc mobile = us.getMobile(); if (mobile.hasNationalNumberPattern()) { String pattern = mobile.getNationalNumberPattern(); }}NF.PhoneDesc
Section titled “NF.PhoneDesc”Describes valid patterns and lengths for one line type within metadata.
| Accessor | Type | libphonenumber |
|---|---|---|
hasNationalNumberPattern / getNationalNumberPattern | String | national_number_pattern |
getPossibleLengthCount / getPossibleLength(Integer index) | Integer | possible_length |
possibleLengths() | List<Integer> | possible_length list |
getPossibleLengthLocalOnlyCount / getPossibleLengthLocalOnly(Integer index) | Integer | possible_length_local_only |
possibleLengthsLocalOnly() | List<Integer> | possible_length_local_only list |
hasExampleNumber / getExampleNumber | String | example_number |
exactlySameAs(NF.PhoneDesc other) | Boolean | structural equality |
NF.NumberFormatRule
Section titled “NF.NumberFormatRule”One national or international display format rule from metadata.
| Accessor | Type | libphonenumber |
|---|---|---|
hasPattern / getPattern | String | pattern |
hasFormat / getFormat | String | format |
getLeadingDigitsPatternCount / getLeadingDigitsPattern(Integer index) | String | leading_digits_pattern |
leadingDigitPatterns() | List<String> | leading_digits_pattern list |
hasNationalPrefixFormattingRule / getNationalPrefixFormattingRule | String | national_prefix_formatting_rule |
hasNationalPrefixOptionalWhenFormatting / getNationalPrefixOptionalWhenFormatting | Boolean | national_prefix_optional_when_formatting |
hasDomesticCarrierCodeFormattingRule / getDomesticCarrierCodeFormattingRule | String | domestic_carrier_code_formatting_rule |