1# Frequently Asked Questions (FAQ) 2 3## Parsing 4 5### Why wasn't the country code removed when parsing? 6 7In some cases, the library cannot tell if the leading digits of a phone number 8are intended to be the country calling code, or the start of the national 9significant number. 10 11This affects primarily German phone numbers, where 49 is both a country calling 12code and an area code, and numbers of variable lengths are valid. The leading 13digits will only be interpreted as a country calling code if the number is not 14already considered a possible number for the region provided when parsing. 15 16If you know that your numbers are always in the form <country calling 17code><national significant number>, it is safe to put a "+" in front to 18indicate this to the library. 19 20### Why does the library treat some non-digit characters as digits? 21 22When parsing, the library does its best to extract a phone number out of the 23given input string. It looks for the phone number in the provided text; it 24doesn't aim to verify whether the string is *only* a phone number. 25 26If the input looks like a vanity number to the library, `parse()` assumes this 27is intentional and converts alpha characters to digits. Please read the 28documentation for `PhoneNumber parse(String, String)` in 29[PhoneNumberUtil](http://github.com/google/libphonenumber/blob/master/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java) 30for details. Also see `Iterable<PhoneNumberMatch> findNumbers(CharSequence, 31String)`. 32 33Some examples: 34 35* `+1 412 535 abcd` is parsed the same as `+1 412 535 2223`. 36 37* If someone fat-fingers and adds an extra alpha character in the *middle*, 38 then the library assumes this was a mistake and fixes it. E.g. the extra `c` 39 in `+1 412 535 c0000` is ignored, and this is parsed the same as `+1 412 535 40 0000`. 41 42* If someone fat-fingers and *replaces* a digit in the middle with an alpha 43 character, and the remaining characters do not make up a valid number, this 44 alpha character is not converted and the resulting number is invalid, e.g. 45 with `+1 412 535 c000`. 46 47Other examples, in reports: 48 49* [#328](http://github.com/google/libphonenumber/issues/328) 50* [#1001](http://github.com/google/libphonenumber/issues/1001) 51* [#1199](http://github.com/google/libphonenumber/issues/1199) 52* [#1813](http://github.com/google/libphonenumber/issues/1813) 53 54### Why wasn't the national prefix removed when parsing? 55 56Usually, when parsing, we remove a country's national or trunk prefix, so we can 57store a normalized form of the number. This is usually, but not always, a 58leading zero. In some situations, we don't remove this, but instead keep it as 59part of the national number: 60 611. If a country does not use a national prefix, or does not use one anymore, we 62 don't remove a leading zero, since then if the user wanted to format the 63 number we would never know to prefix it with this leading zero. 641. If the leading zero is not a national prefix but is needed for dialling from 65 abroad (e.g. in the case of Italy) it is stored in the proto, not removed as 66 a national prefix. 671. If the number is too short to be a valid phone number in this country, we do 68 not remove the national prefix. For instance, although `0` is a national 69 prefix in Australia, we do not remove it from the number `000` which is the 70 emergency number; if we did we would not know that it needs a `0` re-added 71 when formatting since other short-codes do not, and we would be irreparably 72 changing the phone number. 73 74### Why wasn't `00` parsed the same as `+`? 75 76`00` is not an international prefix (IDD) in every region, so it's not 77equivalent to `+`. 78 79For example, if [parsing `0015417540000` as if dialled from the 80US](http://libphonenumber.appspot.com/phonenumberparser?number=0015417540000&country=US), 81the national number is `15417540000` because `00` is not an international prefix 82in the US. 83 84Ascension Island, however, does have `00` as an international prefix, so `00` 85there works the same as `+` and [`0015417540000` as if dialled from 86`AC`](http://libphonenumber.appspot.com/phonenumberparser?number=0015417540000&country=AC) 87gives `5417540000` for the national number. 88 89You can try [the demo](http://libphonenumber.appspot.com/) for more regions. 90Also see `internationalPrefix` in 91[`resources/PhoneNumberMetadata.xml`](http://github.com/google/libphonenumber/blob/master/resources/PhoneNumberMetadata.xml). 92 93## Validation and types of numbers 94 95### What is the difference between isPossibleNumber and isValidNumber? 96 97To understand the behavior of functions, please refer to the documentation in 98the Javadoc/C++ header files. For example, see `isPossibleNumberWithReason` in 99[`PhoneNumberUtil`](https://github.com/google/libphonenumber/blob/master/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java). 100 101### Why does PhoneNumberUtil return false for valid short numbers? 102 103Short numbers are out of scope of 104[`PhoneNumberUtil`](https://github.com/google/libphonenumber/blob/master/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java). 105For short numbers, use 106[`ShortNumberInfo`](https://github.com/google/libphonenumber/blob/master/java/libphonenumber/src/com/google/i18n/phonenumbers/ShortNumberInfo.java). 107 108### What does it mean for a phone number to be valid? 109 110Our phone number library can tell that a number range is valid when there is 111sufficient official documentation, with some latency after this fact is brought 112to our attention via issue reports or notifications (see below for more 113information on where our metadata comes from). A valid number range is one from 114which numbers can be freely assigned by carriers to users. 115 116Do not rely on libphonenumber to determine whether numbers are currently 117assigned to a specific user and reachable. Some products (e.g. 118[Google 2-step verification](https://www.google.com/landing/2step/)) do 119this with a verification step e.g. by sending an SMS or placing an automated 120phone call with a verification code). This is not technically feasible without 121such a verification step given the complicated international world we live in, 122with varying standardization practices in different regions. 123 124#### But my dialled number connected, so isn't it valid? 125 126Not necessarily. 127 128* In some countries extra digits at the end are ignored. For example, dialling 129 `1800 MICROSOFT` in the US connects to `+1 (800) MIC-ROSO`. 130* During renumbering transitions, e.g. when all numbers are getting an extra 131 `9` added to the front, some operators will "fix" old numbers long after 132 they're no longer working for the majority. 133* Numbers that are only locally-diallable e.g. a 7-digit number dialled in the 134 US are not valid, because without the rest of the number it is impossible 135 for the library to canonicalize this. 136 137### When should I use isValidNumberForRegion? 138 139Rarely! Many people have phone numbers that do not belong to the country they 140live in. This applies particularly to mobile numbers, but may also be true 141for VoIP numbers etc. Note also that the regions your application supports may 142not be the same as the regions we support. For example, the Channel Islands such 143as "Jersey" have their own region code - JE. If you allow these users to sign up 144as a British user ("GB"), their phone numbers will not be considered valid for 145the region "JE". 146 147One use-case where this method may be useful is if you want to see if a 148`FIXED_LINE` number for a business matches the country it is in, to try and spot 149data errors. 150 151### Some "valid" numbers are not formatting correctly. 152 153This could be due to number simplification. In order to keep the size of the XML 154files to a reasonable level, it's necessary in some regions (e.g. "DE" or "AT") 155to simplify number ranges. This results in a relatively small amount of false 156positive numbers (i.e. numbers that should be reported as invalid, but which are 157now shown as valid). 158 159This issue here is that (for simplicity) only the number validity information is 160simplified; the formatting information in the XML (leading digits) retains its 161full accuracy and so doesn't cover these numbers. 162 163Note that while it is probably possible to address this and expand the format 164information to cover these numbers as well, it's a rather non-trivial task 165(since the leading digits must not be over simplified so as to capture other 166valid ranges with different formats). Note that this also applies to attributes 167like "national only" or geocoding information. 168 169### What types of phone numbers can SMSs be sent to? 170 171SMSs can be sent to `MOBILE` or `FIXED_LINE_OR_MOBILE` numbers. However, 172in some countries it is possible to configure other types, such as normal 173land-lines, to receive SMSs. 174 175### <a name="fixed_line_or_mobile"></a>Why did I get `FIXED_LINE_OR_MOBILE` as the type of my phone number? 176 177Some number ranges are explicitly defined as being for fixed-line or mobile 178phones. We even represent ranges defined as being "Mostly land-line" in this 179way. 180 181### What is mobile number portability? 182 183The 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). 184 185### Since it's possible to change the carrier for a phone number, how is the data kept up-to-date? 186 187Not 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. 188 189### What about M2M (machine to machine) numbers? 190 191libphonenumber does not support M2M numbers at the moment, but might in the 192future. 193 194One of the reasons libphonenumber doesn't support M2M so far is because no one 195could explain their use to us sufficiently. 196 197We don't require that a number to be supported by the library has a human at the 198other end since we already accept premium rate services and they might go to an 199automated system instead. But to date we only accept ranges that a human might 200call or send an SMS to. 201 202M2M numbers would violate this assumption and we'd have to evaluate the 203consequences for existing APIs and clients if M2M numbers would be considered 204valid by the library. Clients of libphonenumber expect `mobile` and `fixed-line` 205numbers to have certain affordances, such as: Reachable for voice calls 206(and for mobile also SMS) as well as assuming standard cost. This expectation 207is broken by the lack of M2M standardization today. 208 209Many people use this library for formatting the numbers of their contacts, for 210allowing people to sign up for services, for working out how to dial someone in 211a different country, for working out what kind of cost might be associated with 212a number in an advert, etc. We don't think the lack of M2M support hinders any 213of those use-case, but we might be wrong. 214 215If you would like libphonenumber to support M2M numbers, please engage with the 216developer community at [Support M2M numbers]( 217https://issuetracker.google.com/issues/74493346) with further 218information to address our questions and concerns such as: 219 220* **How to implement support?** e.g. new category, new library or method 221 to call - along with pros and cons, and impact on existing APIs 222* **Authoritative and specific documentation** such as government sources since 223 we currently have less than a dozen sources, which have varied definitions 224 225More information and collabortation on this issue would be very welcomed! 226 227### What about numbers that are only valid for a set of subscribers? 228 229There are some numbers that only work for the subcribers of certain operators 230for special operator-specific services. These differ from carrierSpecific since 231they're not shortcodes. We don't support these numbers due to their limited use 232scope, few examples (only the [area code 700](https://en.wikipedia.org/wiki/Area_code_700) 233in the US), and lack of authoritative evidence. 234 235Until there are more examples with authoritative evidence and a proposal on how 236the library should handle these numbers, we won't be able to support these 237similar to our prerequisites for supporting M2M. 238 239Please see [this issue](https://issuetracker.google.com/issues/65238929) for more 240context, and file a new issue if you're able to provide more information than this. 241 242## Representation 243 244### What is the maximum and minimum length of a phone number? 245 246We support parsing and storing numbers from a minimum length of two digits to a 247maximum length of 17 digits currently (excluding country calling code). The ITU 248standard says the national significant number should not be longer than 249fifteen digits, but empirically this has been proven not to be followed by all 250countries. 251 252## Formatting 253 254### Can / should we format phone numbers in a language-specific way? 255 256No, phone number formatting is country-specific and language-independent. E.g. 257formatting a US number in a French way (e.g. the way a France number is 258formatted) for a French user is undefined and wrong. 259 260It is true that in some countries phone numbers are typically written using 261native, not ASCII, digits; our phone number library supports parsing these but 262doesn't support it at formatting time at the moment. 263 264### When does formatting in a country change? 265 266The formatting within a country changes sparingly, but may be announced explicitly 267or noted implicitly in a national numbering plan update that introduces a new number 268length, number type, or other significant change. This may include the grouping and 269punctuation used (e.g. parentheses versus hyphens). 270 271In the event of lack of evidence and/or enforcement by a central government 272regulatory or telecommunication authority, we'll stick with the status quo 273since the community prefers to bias towards stability and avoid flip-flopping 274between formats over time. If the silent majority becomes vocal to support 275new formatting with authoritative evidence, then we'll collaborate with 276community stakeholders on a transition. 277 278An example of this is the shift from using parentheses to hyphens to separate 279area codes within North America. Hyphens may indicate that the area code is 280optional in local circumstances, but this is shifting to become mandatory 281in areas that have had more area code splits. However, the usage of 282parentheses persists and both methods are acceptable. 283 284See [issue #1996](https://github.com/google/libphonenumber/issues/1996) 285for some additional discussion. 286 287### Why does formatNumberForMobileDialing return an empty string for my number? 288 289If we don't think we can guarantee that the number is diallable from the user's 290mobile phone, we won't return anything. This means that for numbers that we 291don't think are internationally diallable, if the user is outside the country 292we will return an empty string. Similarly, in Brazil a carrier code is essential 293for dialling long-distance domestically. If none has been provided at parsing 294time then we will return an empty string. If you get an empty string and are 295okay providing a number that may not be diallable, you can call another of our 296formatting numbers instead. 297 298## Metadata 299 300### <a name="metadata_definition"></a>What do we mean by "metadata"? 301 302We use the word "metadata" to refer to all information about phone numbering in 303a particular country - what the country code, international and national 304dialling prefixes are, what carrier codes are operational, which phone numbers 305are possible or valid for a particular country, how to optimally format them, 306which prefixes represent a particular geographical area, etc. 307 308### Where do we get information from to determine if a number range is valid? 309 310In theory, phone numbering plans are all supposed to be administered through the 311ITU. Many countries' phone numbering plans may be found on the [ITU website]( 312http://www.itu.int/oth/T0202.aspx?parent=T0202). 313 314We receive automatic notifications when a new ITU plan has been filed, which may 315or may not be before it comes into effect. 316 317Not every country files their numbering plans with the ITU nor are the plans 318filed with ITU always up to date. In some countries, the numbering plans are 319directly handled by a government authority, while in others, most of the work 320is done by telecom companies (the government's role being only to distribute 321ranges at the prefix level, with the actual partitioning within the prefix done 322by the telecom). 323 324A large part of the data in `PhoneNumberMetadata.xml` comes from the ITU 325documents, but because they're sometimes insufficient, we also include data from 326other sources, including user bug reports, telecom company home pages and 327government telecommunication authorities. 328 329There is no RFC indicating where the data comes from, or what format they're in. 330 331We'd love to consume machine-readable numbering plan data (assigned ranges, 332carrier & geo mappings). If you can connect us with partners in the industry 333to achieve this, please do so. Thanks! 334 335### Why is this number from Argentina (AR) or Mexico (MX) not identified as the right number type? 336 337Certain countries' mobile and/or fixed line ranges may overlap, which may make 338accurate identification impossible without additional and explicit context such 339as a mobile prefix. We rely on this prefix being present to correctly identify 340the phone number type (rather than returning 341[`FIXED_LINE_OR_MOBILE`](#fixed_line_or_mobile) in ambiguous cases) until our 342metadata can be fine-grained enough to detect when a user has omitted it. 343 344For example, when calling a mobile line from a fixed line in Argentina, you need 345to dial 15 before the subscriber number, or 9 if you're calling from another 346country. Without these additional digits, your call may not connect at all! 347 348Similarly, Mexico has different mobile prefixes needed when calling from a fixed 349line such as 044 when calling locally, 045 when calling from another state, and 3501 when dialing from another country. 351 352Moreover, these countries have different possible lengths for area codes and 353subscriber numbers depending on the city, which further complicate matters (e.g. 354Buenos Aires is 11 followed by eight digits, but Río Gallegos is 2966 followed 355by six digits). 356 357Despite all the aforementioned complexity, users may not provide their phone 358number with all the additional context unless explicitly asked. For instance, 359since SMS messages can be sent in Argentina from a mobile phone without a 360prefix, the user may not supply the mobile prefix. 361 362We are aware of these issues but fixing them is not trivial. In the meantime, we 363recommend the following workarounds to support affected users. 364 365* If you know an Argentina or Mexico number is mobile (e.g. if you're doing 366 signups with device numbers or will send them an SMS verification code), 367 follow these steps: 368 * For raw input strings: 369 * Parse a raw input string into a `PhoneNumber` and follow the next 370 instructions for `PhoneNumber` objects. 371 * For `PhoneNumber` objects: 372 * Check that the library validates a `PhoneNumber` as mobile, by 373 calling `getNumberType`; 374 * If not, format it in national format and prepend a `9` for Argentina 375 or a `1` for Mexico; 376 * Parse the modified string and if the library validates it as mobile, 377 accept the resulting `PhoneNumber` as canonical. 378* Consider prompting for type (mobile or not) in the phone number input UI. 379 380IMPORTANT: Do not add a leading 1 or 9 for displaying or formatting the numbers. 381Depending on the use case, other tokens may be needed. The library will do the 382right thing if the phone number object is as intended. 383 384### Why are Bouvet Island (BV), Pitcairn Island (PN), Antarctica (AQ) etc. not supported? 385 386We only support a country if: 387 388* **The country has a single country calling code.** For instance, Kosovo (XK) 389 has been using three different country codes until 2017 - those of Serbia, 390 Monaco and Slovenia. The relevant numbers will be marked as valid, but as 391 belonging to Serbia, Monaco or Slovenia respectively. When Kosovo starts 392 using its own country calling code of 383 it will be added to the metadata 393 by itself. Similarly, Antarctica doesn't use its assigned country calling 394 code of 672 - instead the bases belonging to different countries have 395 different solutions. For example, Scott Base, belonging to New Zealand, has 396 an area code that is part of the New Zealand phone number plan, and we 397 support those numbers as valid numbers for NZ. 398* **The country still exists.** For example, Yugoslavia (YU), Serbia and 399 Montenegro (CS) and Netherlands Antilles (AN) have been dissolved and no 400 longer exist as political entities so we do not support them. 401* **The country has some phone numbers in use that can be ascribed to it.** 402 For instance, Pitcairn Island has only around thirty inhabitants and they 403 use satellite phones, so there is no numbering plan for Pitcairn Island. 404 Similarly, Bouvet Island is an uninhabited Antarctic volcanic island with no 405 telephone country code and no telephone connection, so we will not support 406 it. 407* **It has an assigned region code.** For instance, previously Kosovo did not 408 have a region code assigned to it, so we could not support it until it was 409 assigned XK by [CLDR](http://cldr.unicode.org/). 410 411We support non-geographical entities that have been assigned country calling 412codes by the ITU where a numbering plan is available, e.g. "800" (International 413Freephone Service) and 870 (Inmarsat SNAC). However we do not support country 414calling codes that are only "reserved", or that no data is available for (namely 415388 - listed as "Group of countries, shared code" and 991 - listed as "Trial of 416a proposed new international telecommunication public correspondence service, 417shared code".) 418 419### Why are Indonesian toll-free numbers beginning with "00x 803" not supported? 420 421Although some numbers beginning with "001 803" or "007 803" do work in Indonesia 422to reach toll-free endpoints, these numbers are hard to support because they 423overlap with the international dialling prefix for Indonesia (IDD). It seems 424that since 803 is unassigned and not a valid country code, some local 425tel-companies in Indonesia hijack 803 and redirect it to their own services. 426 427We have also found evidence that reaching some "00x 803" numbers cost local or 428national tariff, rather than the call being toll-free. 429 430These numbers are not diallable from any other country using their IDD, 431and it's unclear whether all carriers in Indonesia support them. If we ever 432supported them, they would have to be added to the `noInternationalDialling` 433section, and it is likely some changes in the parsing code would have to be 434made to interpret the "00x" as something other than an IDD: this could have 435undesirable side-effects when parsing other numbers. 436 437## Misc 438 439### <a name="reduced_metadata"></a>What is the metadatalite.js/METADATA_LITE option? 440 441For JavaScript, Java and C++ there is the option to use a stripped-down version 442of the metadata. Currently this only removes the example number metadata, so the 443savings are not a lot, but we may revisit this. 444 445*Impact:* 446 447- `getExampleNumber`, `getInvalidExampleNumber`, `getExampleNumberForType`, 448 `getExampleNumberForNonGeoEntity` will return `null` 449- Binary size (or download size for JS) will be slightly smaller 450 451*JS:* 452Simply include metadatalite.js instead of metadata.js in your project. 453 454*C++:* 455Set the compiler flag `USE_METADATA_LITE` to `ON` using ccmake or similar. 456 457*Java:* 458The metadata binary files can be generated using the ant build rules 459`build-phone-metadata` and `build-short-metadata` with `lite-build` set to 460`true`. This can be set in the [build 461file](https://github.com/google/libphonenumber/blob/master/java/build.xml) 462itself. 463 464### Which versions of the Maven jars should I use? 465 466When possible, use the [latest 467version](https://github.com/google/libphonenumber/releases) of 468libphonenumber. 469 470For the other Maven artifacts, to find the version corresponding to a given 471version of libphonenumber, follow these steps: 472 473* Go to the versioned GitHub tag, e.g. 474 https://github.com/google/libphonenumber/find/v8.3.3 475* Type `pom.xml`. This will surface all the `pom.xml` files as they were 476 released at the chosen tag. 477* Find the version you care about in the corresponding `pom.xml` file. Look 478 for `<version>` in the top-level `project` element. For example, to find the 479 version of the carrier jar corresponding to libphonenumber 8.3.3, open 480 `java/carrier/pom.xml` at v8.3.3's search results. This is `1.56`. 481* If you depend on the carrier or geocoder jar, you also need to depend on 482 the prefixmapper jar. 483 484### How do I load libphonenumber resources in my Android app? 485 486#### System considerations 487 488tl;dr: Do not call `PhoneNumberUtil` API on the main thread. 489 490If you get surprising exceptions involving metadata loading, e.g. "missing 491metadata" exceptions when the metadata exists, then it's probably because you're 492loading resources on the main thread. 493 494Please ensure that you don't call `PhoneNumberUtil` API on the main thread. Not 495loading resources in the main thread is the suggested best practice at the 496[Android developer 497guide](http://developer.android.com/guide/components/processes-and-threads.html), 498and will prevent the issue reported in 499[#265](https://github.com/google/libphonenumber/issues/265), 500[#528](https://github.com/google/libphonenumber/issues/528), and 501[#819](https://github.com/google/libphonenumber/issues/819). 502 503#### Optimize loads 504 505You can manage your own resources by supplying your own 506[`MetadataLoader`](http://github.com/google/libphonenumber/blob/master/java/libphonenumber/src/com/google/i18n/phonenumbers/MetadataLoader.java) 507implementation to the `PhoneNumberUtil` instance. It is thus possible for your 508app to load the resources as Android assets, while libphonenumber loads Java 509resources by default. The result is that the files are read as native Android assets 510and so optimized for speed. 511 512Here's the sample code for how to do it: 513 514``` 515PhoneNumberUtil util = PhoneNumberUtil.createInstance(new MetadataLoader() { 516 @Override 517 public InputStream loadMetadata(String metadataFileName) { 518 return Application.getContext().getAssets().open("some/asset/path" + metadataFileName); 519 } 520}); 521``` 522 523You also need to copy the binary metadata files into your app's asset directory, and 524automate updating them from upstream. To avoid net increase of app size, remove them 525from libphonenumber. 526 527### What about Windows? 528 529The libphonenumber team's support of the C++ library on Windows is primarily to 530support Chromium's build environment, and we depend on the community to support 531other Windows build environments / build chains. We list here some known issues 532that would benefit from open-source collaboration. If you can contribute a PR 533or review and test out someone else's PR, please chime in on these links, or 534email the [discussion 535group](https://groups.google.com/group/libphonenumber-discuss): 536 537* [#1000](https://github.com/google/libphonenumber/issues/1000) to provide 538 a Windows DLL. 539* [#1010](https://github.com/google/libphonenumber/issues/1010) to require 540 Visual Studio 2015 update 2 or later on Windows 541* PR [#1090](https://github.com/google/libphonenumber/pull/1090) / 542 [#824](https://github.com/google/libphonenumber/issues/824) to "Replace 543 POSIX directory operations by Boost Filesystem" 544* [#1555](https://github.com/google/libphonenumber/issues/1555) to allow 545 Windows to build cpp library with pthreads for multi-threading 546 547### How to remove a specific example number? 548 549We supply example numbers as part of the library API. While we aim to have numbers 550that are either explicitly allocated by the country as a test number, or look 551fictitious (e.g. 1234567) we also need these numbers to validate correctly. 552This means we sometimes have numbers that do connect to a real person. 553 554If we by chance have actually listed your real number and would like it removed, 555please report this through Google's new [Issue Tracker](http://issuetracker.google.com/issues/new?component=192347). 556Only our internal team will have access to your identity (whereas GitHub usernames are public). 557