11767c5feSopenharmony_ci# Frequently Asked Questions (FAQ) 21767c5feSopenharmony_ci 31767c5feSopenharmony_ci## <a href="#parsing">Parsing</a> 41767c5feSopenharmony_ci 51767c5feSopenharmony_ci### <a href="#country_code_not_removed">Why wasn't the country code removed when parsing?</a> 61767c5feSopenharmony_ci 71767c5feSopenharmony_ciIn some cases, the library cannot tell if the leading digits of a phone number 81767c5feSopenharmony_ciare intended to be the country calling code, or the start of the national 91767c5feSopenharmony_cisignificant number. 101767c5feSopenharmony_ci 111767c5feSopenharmony_ciThis affects primarily German and Indonesian phone numbers, where country 121767c5feSopenharmony_cicalling code (49 and 62 respectively) is also a valid area code, and numbers of 131767c5feSopenharmony_civariable lengths are valid. The leading digits will only be interpreted as a 141767c5feSopenharmony_cicountry calling code if the number is not already considered a possible number 151767c5feSopenharmony_cifor the region provided when parsing. 161767c5feSopenharmony_ci 171767c5feSopenharmony_ciIf you know that your numbers are always in the form <country calling 181767c5feSopenharmony_cicode><national significant number>, it is safe to put a "+" in front to 191767c5feSopenharmony_ciindicate this to the library. 201767c5feSopenharmony_ci 211767c5feSopenharmony_ci### <a href="#non_digits">Why does the library treat some non-digit characters as digits?</a> 221767c5feSopenharmony_ci 231767c5feSopenharmony_ciWhen parsing, the library does its best to extract a phone number out of the 241767c5feSopenharmony_cigiven input string. It looks for the phone number in the provided text; it 251767c5feSopenharmony_cidoesn't aim to verify whether the string is *only* a phone number. 261767c5feSopenharmony_ci 271767c5feSopenharmony_ciIf the input looks like a vanity number to the library, `parse()` assumes this 281767c5feSopenharmony_ciis intentional and converts alpha characters to digits. Please read the 291767c5feSopenharmony_cidocumentation for `PhoneNumber parse(String, String)` in 301767c5feSopenharmony_ci[PhoneNumberUtil](http://github.com/google/libphonenumber/blob/master/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java) 311767c5feSopenharmony_cifor details. Also see `Iterable<PhoneNumberMatch> findNumbers(CharSequence, 321767c5feSopenharmony_ciString)`. 331767c5feSopenharmony_ci 341767c5feSopenharmony_ciSome examples: 351767c5feSopenharmony_ci 361767c5feSopenharmony_ci* `+1 412 535 abcd` is parsed the same as `+1 412 535 2223`. 371767c5feSopenharmony_ci 381767c5feSopenharmony_ci* If someone mistypes and adds an extra alpha character in the *middle*, 391767c5feSopenharmony_ci then the library assumes this was a mistake and fixes it. E.g. the extra `c` 401767c5feSopenharmony_ci in `+1 412 535 c0000` is ignored, and this is parsed the same as `+1 412 535 411767c5feSopenharmony_ci 0000`. 421767c5feSopenharmony_ci 431767c5feSopenharmony_ci* If someone mistypes and *replaces* a digit in the middle with an alpha 441767c5feSopenharmony_ci character, and the remaining characters do not make up a valid number, this 451767c5feSopenharmony_ci alpha character is not converted and the resulting number is invalid, e.g. 461767c5feSopenharmony_ci with `+1 412 535 c000`. 471767c5feSopenharmony_ci 481767c5feSopenharmony_ci 491767c5feSopenharmony_ci### <a href="#prefix_not_removed">Why wasn't the national prefix removed when parsing?</a> 501767c5feSopenharmony_ci 511767c5feSopenharmony_ciUsually, when parsing, we remove a country's national or trunk prefix, so we can 521767c5feSopenharmony_cistore a normalized form of the number. This is usually, but not always, a 531767c5feSopenharmony_cileading zero. In some situations, we don't remove this, but instead keep it as 541767c5feSopenharmony_cipart of the national number: 551767c5feSopenharmony_ci 561767c5feSopenharmony_ci1. If a country does not use a national prefix, or does not use one anymore, we 571767c5feSopenharmony_ci don't remove a leading zero, since then if the user wanted to format the 581767c5feSopenharmony_ci number we would never know to prefix it with this leading zero. 591767c5feSopenharmony_ci1. If the leading zero is not a national prefix but is needed for dialling from 601767c5feSopenharmony_ci abroad (e.g. in the case of Italy) it is stored in the proto, not removed as 611767c5feSopenharmony_ci a national prefix. 621767c5feSopenharmony_ci1. If the number is too short to be a valid phone number in this country, we do 631767c5feSopenharmony_ci not remove the national prefix. For instance, although `0` is a national 641767c5feSopenharmony_ci prefix in Australia, we do not remove it from the number `000` which is the 651767c5feSopenharmony_ci emergency number; if we did we would not know that it needs a `0` re-added 661767c5feSopenharmony_ci when formatting since other short-codes do not, and we would be irreparably 671767c5feSopenharmony_ci changing the phone number. 681767c5feSopenharmony_ci 691767c5feSopenharmony_ci### <a href="#parsing_idds">Why wasn't `00` parsed the same as `+`?</a> 701767c5feSopenharmony_ci 711767c5feSopenharmony_ci`00` is not an international prefix (IDD) in every region, so it's not 721767c5feSopenharmony_ciequivalent to `+`. 731767c5feSopenharmony_ci 741767c5feSopenharmony_ciFor example, if [parsing `0015417540000` as if dialled from the 751767c5feSopenharmony_ciUS](http://libphonenumber.appspot.com/phonenumberparser?number=0015417540000&country=US), 761767c5feSopenharmony_cithe national number is `15417540000` because `00` is not an international prefix 771767c5feSopenharmony_ciin the US. 781767c5feSopenharmony_ci 791767c5feSopenharmony_ciAscension Island, however, does have `00` as an international prefix, so `00` 801767c5feSopenharmony_cithere works the same as `+` and [`0015417540000` as if dialled from 811767c5feSopenharmony_ci`AC`](http://libphonenumber.appspot.com/phonenumberparser?number=0015417540000&country=AC) 821767c5feSopenharmony_cigives `5417540000` for the national number. 831767c5feSopenharmony_ci 841767c5feSopenharmony_ciYou can try [the demo](http://libphonenumber.appspot.com/) for more regions. 851767c5feSopenharmony_ciAlso see `internationalPrefix` in 861767c5feSopenharmony_ci[`resources/PhoneNumberMetadata.xml`](http://github.com/google/libphonenumber/blob/master/resources/PhoneNumberMetadata.xml). 871767c5feSopenharmony_ci 881767c5feSopenharmony_ci## <a href="#validation">Validation and types of numbers</a> 891767c5feSopenharmony_ci 901767c5feSopenharmony_ci### <a href="#possible_vs_valid">What is the difference between isPossibleNumber and isValidNumber?</a> 911767c5feSopenharmony_ci 921767c5feSopenharmony_ciTo understand the behavior of functions, please refer to the documentation in 931767c5feSopenharmony_cithe Javadoc/C++ header files. For example, see `isPossibleNumberWithReason` in 941767c5feSopenharmony_ci[`PhoneNumberUtil`](https://github.com/google/libphonenumber/blob/master/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java). 951767c5feSopenharmony_ci 961767c5feSopenharmony_ci### <a href="#short_numbers">Why does PhoneNumberUtil return false for valid short numbers?</a> 971767c5feSopenharmony_ci 981767c5feSopenharmony_ciShort numbers are out of scope of 991767c5feSopenharmony_ci[`PhoneNumberUtil`](https://github.com/google/libphonenumber/blob/master/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java). 1001767c5feSopenharmony_ciFor short numbers, use 1011767c5feSopenharmony_ci[`ShortNumberInfo`](https://github.com/google/libphonenumber/blob/master/java/libphonenumber/src/com/google/i18n/phonenumbers/ShortNumberInfo.java). 1021767c5feSopenharmony_ci 1031767c5feSopenharmony_ci### <a href="#what_is_valid">What does it mean for a phone number to be valid?</a> 1041767c5feSopenharmony_ci 1051767c5feSopenharmony_ciOur phone number library can tell that a number range is valid when there is 1061767c5feSopenharmony_cisufficient official documentation, with some latency after this fact is brought 1071767c5feSopenharmony_cito our attention via issue reports or notifications (see below for more 1081767c5feSopenharmony_ciinformation on where our metadata comes from). A valid number range is one from 1091767c5feSopenharmony_ciwhich numbers can be freely assigned by carriers to users. 1101767c5feSopenharmony_ci 1111767c5feSopenharmony_ciDo not rely on libphonenumber to determine whether numbers are currently 1121767c5feSopenharmony_ciassigned to a specific user and reachable. Some products (e.g. 1131767c5feSopenharmony_ci[Google 2-step verification](https://www.google.com/landing/2step/)) do 1141767c5feSopenharmony_cithis with a verification step e.g. by sending an SMS or placing an automated 1151767c5feSopenharmony_ciphone call with a verification code). This is not technically feasible without 1161767c5feSopenharmony_cisuch a verification step given the complicated international world we live in, 1171767c5feSopenharmony_ciwith varying standardization practices in different regions. 1181767c5feSopenharmony_ci 1191767c5feSopenharmony_ci#### <a href="#why_not_valid">But my dialled number connected, so isn't it valid?</a> 1201767c5feSopenharmony_ci 1211767c5feSopenharmony_ciNot necessarily. 1221767c5feSopenharmony_ci 1231767c5feSopenharmony_ci* In some countries extra digits at the end are ignored. For example, dialling 1241767c5feSopenharmony_ci `1800 MICROSOFT` in the US connects to `+1 (800) MIC-ROSO`. 1251767c5feSopenharmony_ci* During renumbering transitions, e.g. when all numbers are getting an extra 1261767c5feSopenharmony_ci `9` added to the front, some operators will "fix" old numbers long after 1271767c5feSopenharmony_ci they're no longer working for the majority. 1281767c5feSopenharmony_ci* Numbers that are only locally-diallable e.g. a 7-digit number dialled in the 1291767c5feSopenharmony_ci US are not valid, because without the rest of the number it is impossible 1301767c5feSopenharmony_ci for the library to canonicalize this. 1311767c5feSopenharmony_ci 1321767c5feSopenharmony_ci### <a href="#isvalidnumberforregion">When should I use isValidNumberForRegion?</a> 1331767c5feSopenharmony_ci 1341767c5feSopenharmony_ciRarely! Many people have phone numbers that do not belong to the country they 1351767c5feSopenharmony_cilive in. This applies particularly to mobile numbers, but may also be true 1361767c5feSopenharmony_cifor VoIP numbers etc. Note also that the regions your application supports may 1371767c5feSopenharmony_cinot be the same as the regions we support. For example, the Channel Islands such 1381767c5feSopenharmony_cias "Jersey" have their own region code - JE. If you allow these users to sign up 1391767c5feSopenharmony_cias a British user ("GB"), their phone numbers will not be considered valid for 1401767c5feSopenharmony_cithe region "JE". 1411767c5feSopenharmony_ci 1421767c5feSopenharmony_ciOne use-case where this method may be useful is if you want to see if a 1431767c5feSopenharmony_ci`FIXED_LINE` number for a business matches the country it is in, to try and spot 1441767c5feSopenharmony_cidata errors. 1451767c5feSopenharmony_ci 1461767c5feSopenharmony_ci### <a href="#incorrect_formatting">Some "valid" numbers are not formatting correctly.</a> 1471767c5feSopenharmony_ci 1481767c5feSopenharmony_ciThis could be due to number simplification. In order to keep the size of the XML 1491767c5feSopenharmony_cifiles to a reasonable level, it's necessary in some regions (e.g. "DE" or "AT") 1501767c5feSopenharmony_cito simplify number ranges. This results in a relatively small amount of false 1511767c5feSopenharmony_cipositive numbers (i.e. numbers that should be reported as invalid, but which are 1521767c5feSopenharmony_cinow shown as valid). 1531767c5feSopenharmony_ci 1541767c5feSopenharmony_ciThis issue here is that (for simplicity) only the number validity information is 1551767c5feSopenharmony_cisimplified; the formatting information in the XML (leading digits) retains its 1561767c5feSopenharmony_cifull accuracy and so doesn't cover these numbers. 1571767c5feSopenharmony_ci 1581767c5feSopenharmony_ciNote that while it is probably possible to address this and expand the format 1591767c5feSopenharmony_ciinformation to cover these numbers as well, it's a rather non-trivial task 1601767c5feSopenharmony_ci(since the leading digits must not be over simplified so as to capture other 1611767c5feSopenharmony_civalid ranges with different formats). Note that this also applies to attributes 1621767c5feSopenharmony_cilike "national only" or geocoding information. 1631767c5feSopenharmony_ci 1641767c5feSopenharmony_ci### <a href="#sms_sending">What types of phone numbers can SMSs be sent to?</a> 1651767c5feSopenharmony_ci 1661767c5feSopenharmony_ciSMSs can be sent to `MOBILE` or `FIXED_LINE_OR_MOBILE` numbers. However, 1671767c5feSopenharmony_ciin some countries it is possible to configure other types, such as normal 1681767c5feSopenharmony_ciland-lines, to receive SMSs. 1691767c5feSopenharmony_ci 1701767c5feSopenharmony_ci### <a name="#fixed_line_or_mobile">Why did I get `FIXED_LINE_OR_MOBILE` as the type of my phone number?</a> 1711767c5feSopenharmony_ci 1721767c5feSopenharmony_ciSome number ranges are explicitly defined as being for fixed-line or mobile 1731767c5feSopenharmony_ciphones. We even represent ranges defined as being "Mostly land-line" in this 1741767c5feSopenharmony_ciway. 1751767c5feSopenharmony_ci 1761767c5feSopenharmony_ci### <a name="#portability">What is mobile number portability?</a> 1771767c5feSopenharmony_ci 1781767c5feSopenharmony_ciThe ability to keep your mobile phone number when changing carriers. To see whether a region supports mobile number portability use [isMobileNumberPortableRegion](https://github.com/google/libphonenumber/blob/58247207903f917839001bc62525a5b48a475b7e/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java#L3524). 1791767c5feSopenharmony_ci 1801767c5feSopenharmony_ci### <a name="#carrier_changes">Since it's possible to change the carrier for a phone number, how is the data kept up-to-date?</a> 1811767c5feSopenharmony_ci 1821767c5feSopenharmony_ciNot all regions support mobile number portability. For those that don't, we return the carrier when available. For those that do, we return the original carrier for the supplied number. 1831767c5feSopenharmony_ci 1841767c5feSopenharmony_ci### <a name="#m2m">What about M2M (machine to machine) numbers?</a> 1851767c5feSopenharmony_ci 1861767c5feSopenharmony_cilibphonenumber does not support M2M numbers in general, but only in one exception case where in Netherlands 097X M2M numbers are used as regular mobile phone numbers. 1871767c5feSopenharmony_ci 1881767c5feSopenharmony_ciThe reason for Libphonenumber to not provide M2M support is related to the lack of standardization and the need for a new Util API (not in radar for the time being). 1891767c5feSopenharmony_ci 1901767c5feSopenharmony_ciWe don't require that a number to be supported by the library has a human at the other end since we already accept premium rate services and they might go to an automated system instead. But to date we only accept ranges that a human might call or send an SMS to. 1911767c5feSopenharmony_ci 1921767c5feSopenharmony_ciM2M numbers would violate this assumption and we'd have to evaluate the consequences for existing APIs and clients if M2M numbers would be considered valid by the library. Clients of libphonenumber expect mobile and fixed-line numbers to have certain affordances, such as: Reachable for voice calls (and for mobile also SMS) as well as assuming standard cost. This expectation is broken by the lack of M2M standardization today. 1931767c5feSopenharmony_ci 1941767c5feSopenharmony_ciMany people use this library for formatting the numbers of their contacts, for allowing people to sign up for services, for working out how to dial someone in a different country, for working out what kind of cost might be associated with a number in an advert, etc. We don't think the lack of M2M support hinders any of those use-case, but we might be wrong. 1951767c5feSopenharmony_ci 1961767c5feSopenharmony_ciAt the moment Libphonenumber can only support phone numbers that can be dialled by us, not by machines. If you found any humanly diallable M2M numbers that library is not supporting, please raise an [issue here](http://issuetracker.google.com/issues/new?component=192347) with all authoritative and specific documentation such as government sources, which have varied definitions. 1971767c5feSopenharmony_ci 1981767c5feSopenharmony_ci### <a href="#why_only_nl_m2m">Why supporting only NL M2M numbers?; Are we sure all 097X numbers are MOBILE?</a> 1991767c5feSopenharmony_ci 2001767c5feSopenharmony_ciOfficial authority has [explicitly stated](https://www.acm.nl/en/publications/information-about-dutch-097-numbers-non-dutch-providers) that this range “should be made accessible, just like other, regular number series from the Netherlands” and that “you can set up a voice and SMS connection towards prefix +31-97 in the same way as you have done already with the +31-6 series.[...] you should enable your systems for voice telephony for the numbers 2011767c5feSopenharmony_ciin the +31-97 series”. This means, however, that there might be cases where the library would categorise a number as a valid mobile number, but in reality, the particular number is used as pure M2M, is not SMS or voice-enabled. There is not much we can do from our side about this, since we always follow official guidelines. 2021767c5feSopenharmony_ci 2031767c5feSopenharmony_ciTherefore, clients should be aware that there is possibility of false positives in NL MOBILE category. The library will continue to not support M2M numbers in general. 2041767c5feSopenharmony_ci 2051767c5feSopenharmony_ci### <a href="#operator_specific_numbers">What about numbers that are only valid for a set of subscribers?</a> 2061767c5feSopenharmony_ci 2071767c5feSopenharmony_ciThere are some numbers that only work for the subscribers of certain operators 2081767c5feSopenharmony_cifor special operator-specific services. These differ from carrierSpecific since 2091767c5feSopenharmony_cithey're not shortcodes. We don't support these numbers due to their limited use 2101767c5feSopenharmony_ciscope, few examples (only the [area code 700](https://en.wikipedia.org/wiki/Area_code_700) 2111767c5feSopenharmony_ciin the US), and lack of authoritative evidence. 2121767c5feSopenharmony_ci 2131767c5feSopenharmony_ciUntil there are more examples with authoritative evidence and a proposal on how 2141767c5feSopenharmony_cithe library should handle these numbers, we won't be able to support these 2151767c5feSopenharmony_cisimilar to our prerequisites for supporting M2M. 2161767c5feSopenharmony_ci 2171767c5feSopenharmony_ciPlease see [this issue](https://issuetracker.google.com/issues/65238929) for more 2181767c5feSopenharmony_cicontext, and file a new issue if you're able to provide more information than this. 2191767c5feSopenharmony_ci 2201767c5feSopenharmony_ci## <a name="#representation">Representation</a> 2211767c5feSopenharmony_ci 2221767c5feSopenharmony_ci### <a name="#max_length">What is the maximum and minimum length of a phone number?</a> 2231767c5feSopenharmony_ci 2241767c5feSopenharmony_ciWe support parsing and storing numbers from a minimum length of two digits to a 2251767c5feSopenharmony_cimaximum length of 17 digits currently (excluding country calling code). The ITU 2261767c5feSopenharmony_cistandard says the national significant number should not be longer than 2271767c5feSopenharmony_cififteen digits, but empirically this has been proven not to be followed by all 2281767c5feSopenharmony_cicountries. 2291767c5feSopenharmony_ci 2301767c5feSopenharmony_ci## <a name="#formatting">Formatting</a> 2311767c5feSopenharmony_ci 2321767c5feSopenharmony_ci### <a name="#language_specific_format">Can / should we format phone numbers in a language-specific way?</a> 2331767c5feSopenharmony_ci 2341767c5feSopenharmony_ciNo, phone number formatting is country-specific and language-independent. E.g. 2351767c5feSopenharmony_ciformatting a US number in a French way (e.g. the way a France number is 2361767c5feSopenharmony_ciformatted) for a French user is undefined and wrong. 2371767c5feSopenharmony_ci 2381767c5feSopenharmony_ciIt is true that in some countries phone numbers are typically written using 2391767c5feSopenharmony_cinative, not ASCII, digits; our phone number library supports parsing these but 2401767c5feSopenharmony_cidoesn't support it at formatting time at the moment. 2411767c5feSopenharmony_ci 2421767c5feSopenharmony_ci### <a href="#changes_in_formatting">When does formatting in a country change?</a> 2431767c5feSopenharmony_ci 2441767c5feSopenharmony_ciThe formatting within a country changes sparingly, but may be announced explicitly 2451767c5feSopenharmony_cior noted implicitly in a national numbering plan update that introduces a new number 2461767c5feSopenharmony_cilength, number type, or other significant change. This may include the grouping and 2471767c5feSopenharmony_cipunctuation used (e.g. parentheses versus hyphens). 2481767c5feSopenharmony_ci 2491767c5feSopenharmony_ciIn the event of lack of evidence and/or enforcement by a central government 2501767c5feSopenharmony_ciregulatory or telecommunication authority, we'll stick with the status quo 2511767c5feSopenharmony_cisince the community prefers to bias towards stability and avoid flip-flopping 2521767c5feSopenharmony_cibetween formats over time. If the silent majority becomes vocal to support 2531767c5feSopenharmony_cinew formatting with authoritative evidence, then we'll collaborate with 2541767c5feSopenharmony_cicommunity stakeholders on a transition. 2551767c5feSopenharmony_ci 2561767c5feSopenharmony_ciAn example of this is the shift from using parentheses to hyphens to separate 2571767c5feSopenharmony_ciarea codes within North America. Hyphens may indicate that the area code is 2581767c5feSopenharmony_cioptional in local circumstances, but this is shifting to become mandatory 2591767c5feSopenharmony_ciin areas that have had more area code splits. However, the usage of 2601767c5feSopenharmony_ciparentheses persists and both methods are acceptable. 2611767c5feSopenharmony_ci 2621767c5feSopenharmony_ciSee [issue #1996](https://github.com/google/libphonenumber/issues/1996) 2631767c5feSopenharmony_cifor some additional discussion. 2641767c5feSopenharmony_ci 2651767c5feSopenharmony_ci### <a name="#empty_format_result">Why does formatNumberForMobileDialing return an empty string for my number?</a> 2661767c5feSopenharmony_ci 2671767c5feSopenharmony_ciIf we don't think we can guarantee that the number is diallable from the user's 2681767c5feSopenharmony_cimobile phone, we won't return anything. This means that for numbers that we 2691767c5feSopenharmony_cidon't think are internationally diallable, if the user is outside the country 2701767c5feSopenharmony_ciwe will return an empty string. Similarly, in Brazil a carrier code is essential 2711767c5feSopenharmony_cifor dialling long-distance domestically. If none has been provided at parsing 2721767c5feSopenharmony_citime then we will return an empty string. If you get an empty string and are 2731767c5feSopenharmony_ciokay providing a number that may not be diallable, you can call another of our 2741767c5feSopenharmony_ciformatting numbers instead. 2751767c5feSopenharmony_ci 2761767c5feSopenharmony_ci## <a name="#metadata">Metadata</a> 2771767c5feSopenharmony_ci 2781767c5feSopenharmony_ci### <a name="#metadata_definition">What do we mean by "metadata"?</a> 2791767c5feSopenharmony_ci 2801767c5feSopenharmony_ciWe use the word "metadata" to refer to all information about phone numbering in 2811767c5feSopenharmony_cia particular country - what the country code, international and national 2821767c5feSopenharmony_cidialling prefixes are, what carrier codes are operational, which phone numbers 2831767c5feSopenharmony_ciare possible or valid for a particular country, how to optimally format them, 2841767c5feSopenharmony_ciwhich prefixes represent a particular geographical area, etc. 2851767c5feSopenharmony_ci 2861767c5feSopenharmony_ci### <a name="#metadata_sources">Where do we get information from to determine if a number range is valid?</a> 2871767c5feSopenharmony_ci 2881767c5feSopenharmony_ciIn theory, phone numbering plans are all supposed to be administered through the 2891767c5feSopenharmony_ciITU. Many countries' phone numbering plans may be found on the [ITU website]( 2901767c5feSopenharmony_cihttp://www.itu.int/oth/T0202.aspx?parent=T0202). 2911767c5feSopenharmony_ci 2921767c5feSopenharmony_ciWe receive automatic notifications when a new ITU plan has been filed, which may 2931767c5feSopenharmony_cior may not be before it comes into effect. 2941767c5feSopenharmony_ci 2951767c5feSopenharmony_ciNot every country files their numbering plans with the ITU nor are the plans 2961767c5feSopenharmony_cifiled with ITU always up to date. In some countries, the numbering plans are 2971767c5feSopenharmony_cidirectly handled by a government authority, while in others, most of the work 2981767c5feSopenharmony_ciis done by telecom companies (the government's role being only to distribute 2991767c5feSopenharmony_ciranges at the prefix level, with the actual partitioning within the prefix done 3001767c5feSopenharmony_ciby the telecom). 3011767c5feSopenharmony_ci 3021767c5feSopenharmony_ciA large part of the data in `PhoneNumberMetadata.xml` comes from the ITU 3031767c5feSopenharmony_cidocuments, but because they're sometimes insufficient, we also include data from 3041767c5feSopenharmony_ciother sources, including user bug reports, telecom company home pages and 3051767c5feSopenharmony_cigovernment telecommunication authorities. 3061767c5feSopenharmony_ci 3071767c5feSopenharmony_ciThere is no RFC indicating where the data comes from, or what format they're in. 3081767c5feSopenharmony_ci 3091767c5feSopenharmony_ciWe'd love to consume machine-readable numbering plan data (assigned ranges, 3101767c5feSopenharmony_cicarrier & geo mappings). If you can connect us with partners in the industry 3111767c5feSopenharmony_cito achieve this, please do so. Thanks! 3121767c5feSopenharmony_ci 3131767c5feSopenharmony_ci### <a name="#mx_and_ar">Why is this number from Argentina (AR) or Mexico (MX) not identified as the right number type?</a> 3141767c5feSopenharmony_ci 3151767c5feSopenharmony_ciCertain countries' mobile and/or fixed line ranges may overlap or too granular, 3161767c5feSopenharmony_ciwhich may make accurate identification impossible. Eg: Argentina and Mexico. 3171767c5feSopenharmony_ciWe tried incorporating such granular data (prefix of 7 digit for a 10 digit 3181767c5feSopenharmony_cinumber). However, due to very high maintainance to keep the data fresh and 3191767c5feSopenharmony_cialso leading to significant increase in metadata size, we are supporting 3201767c5feSopenharmony_ciranges/prefixes only at higher level. More details in [Argentina](https://issuetracker.google.com/issues/78443410) and 3211767c5feSopenharmony_ci[Mexico](https://issuetracker.google.com/issues/74517266) triaged issues. 3221767c5feSopenharmony_ci 3231767c5feSopenharmony_ci@Argentina, 3241767c5feSopenharmony_ciWhen calling a mobile line from a fixed line in Argentina, you need 3251767c5feSopenharmony_cito dial 15 before the subscriber number, or 9 if you're calling from another 3261767c5feSopenharmony_cicountry. Without these additional digits, your call may not connect at all! 3271767c5feSopenharmony_ci 3281767c5feSopenharmony_ciWe rely on these additional and explicit context such as a mobile prefix to 3291767c5feSopenharmony_cicorrectly identify the phone number type (rather than returning [`FIXED_LINE_OR_MOBILE`](#fixed_line_or_mobile) 3301767c5feSopenharmony_ciin ambiguous cases). 3311767c5feSopenharmony_ci 3321767c5feSopenharmony_ciMoreover, Argentina has different possible lengths for area codes and 3331767c5feSopenharmony_cisubscriber numbers depending on the city, which further complicate matters (e.g. 3341767c5feSopenharmony_ciBuenos Aires is 11 followed by eight digits, but Río Gallegos is 2966 followed 3351767c5feSopenharmony_ciby six digits). 3361767c5feSopenharmony_ci 3371767c5feSopenharmony_ciDespite all the aforementioned complexity, users may not provide their phone 3381767c5feSopenharmony_cinumber with all the additional context unless explicitly asked. For instance, 3391767c5feSopenharmony_cisince SMS messages can be sent in Argentina from a mobile phone without a 3401767c5feSopenharmony_ciprefix, the user may not supply the mobile prefix. 3411767c5feSopenharmony_ci 3421767c5feSopenharmony_ciWe are aware of these issues but fixing them is not trivial. In the meantime, we 3431767c5feSopenharmony_cirecommend the following workarounds to support affected users. 3441767c5feSopenharmony_ci 3451767c5feSopenharmony_ci* If you know an Argentina number is mobile (e.g. if you're doing signups with 3461767c5feSopenharmony_ci device numbers or will send them an SMS verification code), follow these steps: 3471767c5feSopenharmony_ci * For raw input strings: 3481767c5feSopenharmony_ci * Parse a raw input string into a `PhoneNumber` and follow the next 3491767c5feSopenharmony_ci instructions for `PhoneNumber` objects. 3501767c5feSopenharmony_ci * For `PhoneNumber` objects: 3511767c5feSopenharmony_ci * Check that the library validates a `PhoneNumber` as mobile, by 3521767c5feSopenharmony_ci calling `getNumberType`; 3531767c5feSopenharmony_ci * If not, format it in national format and prepend a `9` 3541767c5feSopenharmony_ci * Parse the modified string and if the library validates it as mobile, 3551767c5feSopenharmony_ci accept the resulting `PhoneNumber` as canonical. 3561767c5feSopenharmony_ci* Consider prompting for type (mobile or not) in the phone number input UI. 3571767c5feSopenharmony_ci 3581767c5feSopenharmony_ciIMPORTANT: Do not add a leading 9 for displaying or formatting the numbers. 3591767c5feSopenharmony_ciDepending on the use case, other tokens may be needed. The library will do the 3601767c5feSopenharmony_ciright thing if the phone number object is as intended. 3611767c5feSopenharmony_ci 3621767c5feSopenharmony_ci@Mexico, 3631767c5feSopenharmony_ciMexico used to have such additional prefixes (1, 02, 045, ...) for dialling 3641767c5feSopenharmony_cimobile numbers internationally, fixed-line to mobile nationally.. As these 3651767c5feSopenharmony_cidialling patterns were deprecated, we have continued to maintain mobile and 3661767c5feSopenharmony_cifixed-line ranges at higher level, returning type as [`FIXED_LINE_OR_MOBILE`](#fixed_line_or_mobile) 3671767c5feSopenharmony_ci 3681767c5feSopenharmony_ci### <a href="#mx_legacy_formats">Why Mexico (MX) numbers in older dialling formats are accepted as valid ones?</a> 3691767c5feSopenharmony_ciThough library has stopped supporting below older dialling codes in the canonical 3701767c5feSopenharmony_ciform and formatting results, we are lenient in parsing the number, i.e removing 3711767c5feSopenharmony_ciall older codes. 3721767c5feSopenharmony_ci- 1 -> in E.164 international diallings 3731767c5feSopenharmony_ci- 01, 02, 044 and 045 -> for local/national diallings 3741767c5feSopenharmony_ci 3751767c5feSopenharmony_ciThis is because we found the older dialling codes supported even after deprecation 3761767c5feSopenharmony_ciperiod, so we decided to support them for longer time. However, we will stop this as 3771767c5feSopenharmony_cipart of [this issue](https://issuetracker.google.com/issues/205606725). More details there. 3781767c5feSopenharmony_ci 3791767c5feSopenharmony_ci### <a name="#unsupported_regions">Why are Bouvet Island (BV), Pitcairn Island (PN), Antarctica (AQ) etc. not supported?</a> 3801767c5feSopenharmony_ci 3811767c5feSopenharmony_ciWe only support a country if: 3821767c5feSopenharmony_ci 3831767c5feSopenharmony_ci* **The country has a single country calling code.** For instance, Kosovo (XK) 3841767c5feSopenharmony_ci has been using three different country codes until 2017 - those of Serbia, 3851767c5feSopenharmony_ci Monaco and Slovenia. The relevant numbers will be marked as valid, but as 3861767c5feSopenharmony_ci belonging to Serbia, Monaco or Slovenia respectively. When Kosovo starts 3871767c5feSopenharmony_ci using its own country calling code of 383 it will be added to the metadata 3881767c5feSopenharmony_ci by itself. Similarly, Antarctica doesn't use its assigned country calling 3891767c5feSopenharmony_ci code of 672 - instead the bases belonging to different countries have 3901767c5feSopenharmony_ci different solutions. For example, Scott Base, belonging to New Zealand, has 3911767c5feSopenharmony_ci an area code that is part of the New Zealand phone number plan, and we 3921767c5feSopenharmony_ci support those numbers as valid numbers for NZ. 3931767c5feSopenharmony_ci* **The country still exists.** For example, Yugoslavia (YU), Serbia and 3941767c5feSopenharmony_ci Montenegro (CS) and Netherlands Antilles (AN) have been dissolved and no 3951767c5feSopenharmony_ci longer exist as political entities so we do not support them. 3961767c5feSopenharmony_ci* **The country has some phone numbers in use that can be ascribed to it.** 3971767c5feSopenharmony_ci For instance, Pitcairn Island has only around thirty inhabitants and they 3981767c5feSopenharmony_ci use satellite phones, so there is no numbering plan for Pitcairn Island. 3991767c5feSopenharmony_ci Similarly, Bouvet Island is an uninhabited Antarctic volcanic island with no 4001767c5feSopenharmony_ci telephone country code and no telephone connection, so we will not support 4011767c5feSopenharmony_ci it. 4021767c5feSopenharmony_ci* **It has an assigned region code.** For instance, previously Kosovo did not 4031767c5feSopenharmony_ci have a region code assigned to it, so we could not support it until it was 4041767c5feSopenharmony_ci assigned XK by [CLDR](http://cldr.unicode.org/). 4051767c5feSopenharmony_ci 4061767c5feSopenharmony_ciWe support non-geographical entities that have been assigned country calling 4071767c5feSopenharmony_cicodes by the ITU where a numbering plan is available, e.g. "800" (International 4081767c5feSopenharmony_ciFreephone Service) and 870 (Inmarsat SNAC). However we do not support country 4091767c5feSopenharmony_cicalling codes that are only "reserved", or that no data is available for (namely 4101767c5feSopenharmony_ci388 - listed as "Group of countries, shared code" and 991 - listed as "Trial of 4111767c5feSopenharmony_cia proposed new international telecommunication public correspondence service, 4121767c5feSopenharmony_cishared code".) 4131767c5feSopenharmony_ci 4141767c5feSopenharmony_ci### <a name="#indonesia_tollfree">Why are Indonesian toll-free numbers beginning with "00x 803" not supported?</a> 4151767c5feSopenharmony_ci 4161767c5feSopenharmony_ciAlthough some numbers beginning with "001 803" or "007 803" do work in Indonesia 4171767c5feSopenharmony_cito reach toll-free endpoints, these numbers are hard to support because they 4181767c5feSopenharmony_cioverlap with the international dialling prefix for Indonesia (IDD). It seems 4191767c5feSopenharmony_cithat since 803 is unassigned and not a valid country code, some local 4201767c5feSopenharmony_citel-companies in Indonesia hijack 803 and redirect it to their own services. 4211767c5feSopenharmony_ci 4221767c5feSopenharmony_ciWe have also found evidence that reaching some "00x 803" numbers cost local or 4231767c5feSopenharmony_cinational tariff, rather than the call being toll-free. 4241767c5feSopenharmony_ci 4251767c5feSopenharmony_ciThese numbers are not diallable from any other country using their IDD, 4261767c5feSopenharmony_ciand it's unclear whether all carriers in Indonesia support them. If we ever 4271767c5feSopenharmony_cisupported them, they would have to be added to the `noInternationalDialling` 4281767c5feSopenharmony_cisection, and it is likely some changes in the parsing code would have to be 4291767c5feSopenharmony_cimade to interpret the "00x" as something other than an IDD: this could have 4301767c5feSopenharmony_ciundesirable side-effects when parsing other numbers. 4311767c5feSopenharmony_ci 4321767c5feSopenharmony_ci## <a name="#misc">Misc</a> 4331767c5feSopenharmony_ci 4341767c5feSopenharmony_ci### <a name="#reduced_metadata">What is the metadatalite.js/METADATA_LITE option?</a> 4351767c5feSopenharmony_ci 4361767c5feSopenharmony_ciFor JavaScript, Java and C++ there is the option to use a stripped-down version 4371767c5feSopenharmony_ciof the metadata. Currently this only removes the example number metadata, so the 4381767c5feSopenharmony_cisavings are not a lot, but we may revisit this. 4391767c5feSopenharmony_ci 4401767c5feSopenharmony_ci*Impact:* 4411767c5feSopenharmony_ci 4421767c5feSopenharmony_ci- `getExampleNumber`, `getInvalidExampleNumber`, `getExampleNumberForType`, 4431767c5feSopenharmony_ci `getExampleNumberForNonGeoEntity` will return `null` 4441767c5feSopenharmony_ci- Binary size (or download size for JS) will be slightly smaller 4451767c5feSopenharmony_ci 4461767c5feSopenharmony_ci*JS:* 4471767c5feSopenharmony_ciSimply include metadatalite.js instead of metadata.js in your project. 4481767c5feSopenharmony_ci 4491767c5feSopenharmony_ci*C++:* 4501767c5feSopenharmony_ciSet the compiler flag `USE_METADATA_LITE` to `ON` using ccmake or similar. 4511767c5feSopenharmony_ci 4521767c5feSopenharmony_ci*Java:* 4531767c5feSopenharmony_ciThe metadata binary files can be generated using the ant build rules 4541767c5feSopenharmony_ci`build-phone-metadata` and `build-short-metadata` with `lite-build` set to 4551767c5feSopenharmony_ci`true`. This can be set in the [build 4561767c5feSopenharmony_cifile](https://github.com/google/libphonenumber/blob/master/java/build.xml) 4571767c5feSopenharmony_ciitself. 4581767c5feSopenharmony_ci 4591767c5feSopenharmony_ci### <a name="#maven">Which versions of the Maven jars should I use?</a> 4601767c5feSopenharmony_ci 4611767c5feSopenharmony_ciWhen possible, use the [latest 4621767c5feSopenharmony_civersion](https://github.com/google/libphonenumber/releases) of 4631767c5feSopenharmony_cilibphonenumber. 4641767c5feSopenharmony_ci 4651767c5feSopenharmony_ciFor the other Maven artifacts, to find the version corresponding to a given 4661767c5feSopenharmony_civersion of libphonenumber, follow these steps: 4671767c5feSopenharmony_ci 4681767c5feSopenharmony_ci* Go to the versioned GitHub tag, e.g. 4691767c5feSopenharmony_ci https://github.com/google/libphonenumber/find/v8.3.3 4701767c5feSopenharmony_ci* Type `pom.xml`. This will surface all the `pom.xml` files as they were 4711767c5feSopenharmony_ci released at the chosen tag. 4721767c5feSopenharmony_ci* Find the version you care about in the corresponding `pom.xml` file. Look 4731767c5feSopenharmony_ci for `<version>` in the top-level `project` element. For example, to find the 4741767c5feSopenharmony_ci version of the carrier jar corresponding to libphonenumber 8.3.3, open 4751767c5feSopenharmony_ci `java/carrier/pom.xml` at v8.3.3's search results. This is `1.56`. 4761767c5feSopenharmony_ci* If you depend on the carrier or geocoder jar, you also need to depend on 4771767c5feSopenharmony_ci the prefixmapper jar. 4781767c5feSopenharmony_ci 4791767c5feSopenharmony_ci### <a name="#android">How do I load libphonenumber resources in my Android app?</a> 4801767c5feSopenharmony_ci 4811767c5feSopenharmony_ci#### System considerations 4821767c5feSopenharmony_ci 4831767c5feSopenharmony_citl;dr: Do not call `PhoneNumberUtil` API on the main thread. 4841767c5feSopenharmony_ci 4851767c5feSopenharmony_ciIf you get surprising exceptions involving metadata loading, e.g. "missing 4861767c5feSopenharmony_cimetadata" exceptions when the metadata exists, then it's probably because you're 4871767c5feSopenharmony_ciloading resources on the main thread. 4881767c5feSopenharmony_ci 4891767c5feSopenharmony_ciPlease ensure that you don't call `PhoneNumberUtil` API on the main thread. Not 4901767c5feSopenharmony_ciloading resources in the main thread is the suggested best practice at the 4911767c5feSopenharmony_ci[Android developer 4921767c5feSopenharmony_ciguide](http://developer.android.com/guide/components/processes-and-threads.html), 4931767c5feSopenharmony_ciand will prevent the issue reported in 4941767c5feSopenharmony_ci[#265](https://github.com/google/libphonenumber/issues/265), 4951767c5feSopenharmony_ci[#528](https://github.com/google/libphonenumber/issues/528), and 4961767c5feSopenharmony_ci[#819](https://github.com/google/libphonenumber/issues/819). 4971767c5feSopenharmony_ci 4981767c5feSopenharmony_ci#### Optimize loads 4991767c5feSopenharmony_ci 5001767c5feSopenharmony_ciYou can manage your own resources by supplying your own 5011767c5feSopenharmony_ci[`MetadataLoader`](http://github.com/google/libphonenumber/blob/master/java/libphonenumber/src/com/google/i18n/phonenumbers/MetadataLoader.java) 5021767c5feSopenharmony_ciimplementation to the `PhoneNumberUtil` instance. It is thus possible for your 5031767c5feSopenharmony_ciapp to load the resources as Android assets, while libphonenumber loads Java 5041767c5feSopenharmony_ciresources by default. The result is that the files are read as native Android assets 5051767c5feSopenharmony_ciand so optimized for speed. 5061767c5feSopenharmony_ci 5071767c5feSopenharmony_ciHere's the sample code for how to do it: 5081767c5feSopenharmony_ci 5091767c5feSopenharmony_ci``` 5101767c5feSopenharmony_ciPhoneNumberUtil util = PhoneNumberUtil.createInstance(new MetadataLoader() { 5111767c5feSopenharmony_ci @Override 5121767c5feSopenharmony_ci public InputStream loadMetadata(String metadataFileName) { 5131767c5feSopenharmony_ci return Application.getContext().getAssets().open("some/asset/path" + metadataFileName); 5141767c5feSopenharmony_ci } 5151767c5feSopenharmony_ci}); 5161767c5feSopenharmony_ci``` 5171767c5feSopenharmony_ci 5181767c5feSopenharmony_ciYou also need to copy the binary metadata files into your app's asset directory, and 5191767c5feSopenharmony_ciautomate updating them from upstream. To avoid net increase of app size, remove them 5201767c5feSopenharmony_cifrom libphonenumber. 5211767c5feSopenharmony_ci 5221767c5feSopenharmony_ci### <a name="#windows">What about Windows?</a> 5231767c5feSopenharmony_ci 5241767c5feSopenharmony_ciThe libphonenumber team's support of the C++ library on Windows is primarily to 5251767c5feSopenharmony_cisupport Chromium's build environment, and we depend on the community to support 5261767c5feSopenharmony_ciother Windows build environments / build chains. We list here some known issues 5271767c5feSopenharmony_cithat would benefit from open-source collaboration. If you can contribute a PR 5281767c5feSopenharmony_cior review and test out someone else's PR, please chime in on these links, or 5291767c5feSopenharmony_ciemail the [discussion 5301767c5feSopenharmony_cigroup](https://groups.google.com/group/libphonenumber-discuss): 5311767c5feSopenharmony_ci 5321767c5feSopenharmony_ci* [#1000](https://github.com/google/libphonenumber/issues/1000) to provide 5331767c5feSopenharmony_ci a Windows DLL. 5341767c5feSopenharmony_ci* [#1010](https://github.com/google/libphonenumber/issues/1010) to require 5351767c5feSopenharmony_ci Visual Studio 2015 update 2 or later on Windows 5361767c5feSopenharmony_ci* PR [#1090](https://github.com/google/libphonenumber/pull/1090) / 5371767c5feSopenharmony_ci [#824](https://github.com/google/libphonenumber/issues/824) to "Replace 5381767c5feSopenharmony_ci POSIX directory operations by Boost Filesystem" 5391767c5feSopenharmony_ci* [#1555](https://github.com/google/libphonenumber/issues/1555) to allow 5401767c5feSopenharmony_ci Windows to build cpp library with pthreads for multi-threading 5411767c5feSopenharmony_ci 5421767c5feSopenharmony_ci### <a name="#remove_example_number">How to remove a specific example number</a> 5431767c5feSopenharmony_ci 5441767c5feSopenharmony_ciWe supply example numbers as part of the library API. While we aim to have numbers 5451767c5feSopenharmony_cithat are either explicitly allocated by the country as a test number, or look 5461767c5feSopenharmony_cifictitious (e.g. 1234567) we also need these numbers to validate correctly. 5471767c5feSopenharmony_ciThis means we sometimes have numbers that do connect to a real person. 5481767c5feSopenharmony_ci 5491767c5feSopenharmony_ciIf we by chance have actually listed your real number and would like it removed, 5501767c5feSopenharmony_ciplease report this through Google's new [Issue Tracker](http://issuetracker.google.com/issues/new?component=192347). 5511767c5feSopenharmony_ciOnly our internal team will have access to your identity (whereas GitHub usernames are public). 5521767c5feSopenharmony_ci 5531767c5feSopenharmony_ci### <a name="#long_numbers_in_js">Why can the smallest digits of parsed numbers that are very long be incorrect when parsing in Javascript?</a> 5541767c5feSopenharmony_ci 5551767c5feSopenharmony_ciEg: National number of 900184080594493**87**, ```region: JP``` is parsed as 5561767c5feSopenharmony_ci900184080594493**90**. Reason: When the provided number is more than the max 5571767c5feSopenharmony_cilimit of JavaScript ```Number``` type - 2^53, JS starts rounding the value. 5581767c5feSopenharmony_cilibphonenumber cannot do anything better here. More details mentioned [in this issue](https://issuetracker.google.com/issues/198423548). 559