11767c5feSopenharmony_ci# Falsehoods Programmers Believe About Phone Numbers 21767c5feSopenharmony_ci 31767c5feSopenharmony_ci... and tips on how to use libphonenumber. 41767c5feSopenharmony_ci 51767c5feSopenharmony_ciGiven how ubiquitous phone numbers are and how long they've been around, it's 61767c5feSopenharmony_cisurprising how many false assumptions programmers continue to make about them. 71767c5feSopenharmony_ci 81767c5feSopenharmony_ci1. **An individual has a phone number** 91767c5feSopenharmony_ci 101767c5feSopenharmony_ci Some people do not own phones, or do not wish to provide you with their 111767c5feSopenharmony_ci telephone number when asked. Do not require a user to provide a phone number 121767c5feSopenharmony_ci unless it is essential, and whenever possible try to provide a fallback 131767c5feSopenharmony_ci to accommodate these users. 141767c5feSopenharmony_ci 151767c5feSopenharmony_ci1. **You can make a call to any phone number** 161767c5feSopenharmony_ci 171767c5feSopenharmony_ci Some devices such as EFTPOS terminals, fax machines and mobile internet 181767c5feSopenharmony_ci dongles may not support receiving calls. In addition, some people can not 191767c5feSopenharmony_ci use their phones for phone calls. This may be permanent (such as a hearing 201767c5feSopenharmony_ci disability), temporary (temporary hearing loss) or situational (when the 211767c5feSopenharmony_ci user is in a noisy environment). 221767c5feSopenharmony_ci 231767c5feSopenharmony_ci **Tip:** Make how you use phone numbers apparent to the user and give them 241767c5feSopenharmony_ci the option to set their preference. Ensure that you look up this preference 251767c5feSopenharmony_ci before attempting to communicate with the user. 261767c5feSopenharmony_ci 271767c5feSopenharmony_ci1. **An individual has only one phone number** 281767c5feSopenharmony_ci 291767c5feSopenharmony_ci Obviously, this isn't necessarily true. 301767c5feSopenharmony_ci 311767c5feSopenharmony_ci1. **A phone number uniquely identifies an individual** 321767c5feSopenharmony_ci 331767c5feSopenharmony_ci It wasn't even that long ago that mobile phones didn't exist, and it was 341767c5feSopenharmony_ci common for an entire household to share one fixed-line telephone number. In 351767c5feSopenharmony_ci some parts of the world, this is still true, and relatives (or even friends) 361767c5feSopenharmony_ci share a single phone number. Many phone services (especially for businesses) 371767c5feSopenharmony_ci allow multiple inbound calls to or outbound calls from the same phone 381767c5feSopenharmony_ci number. 391767c5feSopenharmony_ci 401767c5feSopenharmony_ci1. **Phone numbers cannot be re-used** 411767c5feSopenharmony_ci 421767c5feSopenharmony_ci Old phone numbers are recycled and get reassigned to other people. 431767c5feSopenharmony_ci 441767c5feSopenharmony_ci1. **Phone numbers that are valid today will always be valid. Phone numbers of 451767c5feSopenharmony_ci a certain type today (e.g., mobile) will never be reassigned to another 461767c5feSopenharmony_ci type.** 471767c5feSopenharmony_ci 481767c5feSopenharmony_ci A phone number which connects today may be disconnected tomorrow. A number 491767c5feSopenharmony_ci which is free to call today may cost money to call tomorrow. The phone 501767c5feSopenharmony_ci company may decide to expand the range of available phone numbers by 511767c5feSopenharmony_ci inserting a digit into an existing number. 521767c5feSopenharmony_ci 531767c5feSopenharmony_ci **Tip:** Don’t store properties for a phone number such as validity or 541767c5feSopenharmony_ci type. Check this information again from the library when you need it. 551767c5feSopenharmony_ci 561767c5feSopenharmony_ci1. **Each country calling code corresponds to exactly one country** 571767c5feSopenharmony_ci 581767c5feSopenharmony_ci The USA, Canada, and several Caribbean islands share the country calling 591767c5feSopenharmony_ci code +1. Russia and Kazakhstan share +7. These are not the only examples! 601767c5feSopenharmony_ci 611767c5feSopenharmony_ci1. **Each country has only one country calling code** 621767c5feSopenharmony_ci 631767c5feSopenharmony_ci As of this present moment (in Mar. 2016), phones in the disputed territory 641767c5feSopenharmony_ci and partially recognised state of Kosovo may be reached by dialing the 651767c5feSopenharmony_ci country calling code for Serbia (+381), Slovenia (+386), or Monaco (+377), 661767c5feSopenharmony_ci depending on where and when one obtained the number. 671767c5feSopenharmony_ci 681767c5feSopenharmony_ci **Tip:** Use a phone widget to encourage users to enter their phone number 691767c5feSopenharmony_ci in an international format such that it can be unambiguously understood. 701767c5feSopenharmony_ci 711767c5feSopenharmony_ci1. **A phone number is dialable from anywhere** 721767c5feSopenharmony_ci 731767c5feSopenharmony_ci Some numbers can only be dialed within the country. Some can only be dialled 741767c5feSopenharmony_ci from within a subset of countries, such as the +800 [Universal 751767c5feSopenharmony_ci International Freephone Numbers](https://en.wikipedia.org/wiki/Toll-free_telephone_number#Universal_International_Freephone_Service). 761767c5feSopenharmony_ci Some may be dialable only if the caller is a subscriber to a particular 771767c5feSopenharmony_ci telecom company. 781767c5feSopenharmony_ci 791767c5feSopenharmony_ci1. **You can send a text message to any phone number** 801767c5feSopenharmony_ci 811767c5feSopenharmony_ci A lot of people still only have a fixed-line telephone, which typically cannot 821767c5feSopenharmony_ci send or receive text messages. 831767c5feSopenharmony_ci 841767c5feSopenharmony_ci **Tip:** Whenever possible, try to accommodate these users by calling them 851767c5feSopenharmony_ci with a voice message or voice prompts. Alternatively, if your service 861767c5feSopenharmony_ci requires sending text messages, verify that the number can receive text 871767c5feSopenharmony_ci messages after the user provides it. 881767c5feSopenharmony_ci 891767c5feSopenharmony_ci1. **Only mobile phones can receive text messages** 901767c5feSopenharmony_ci 911767c5feSopenharmony_ci Some service providers support sending and receiving text messages to fixed-line 921767c5feSopenharmony_ci numbers. There are also online services like Skype that can send and receive 931767c5feSopenharmony_ci text messages. 941767c5feSopenharmony_ci 951767c5feSopenharmony_ci1. **There are only two ways to dial a phone number: domestically and from 961767c5feSopenharmony_ci overseas** 971767c5feSopenharmony_ci 981767c5feSopenharmony_ci Some numbers may need different prefixes depending on: the carrier you are 991767c5feSopenharmony_ci using; what device you are dialling from/to; whether you are inside or 1001767c5feSopenharmony_ci outside a particular geographical region. 1011767c5feSopenharmony_ci 1021767c5feSopenharmony_ci Examples: 1031767c5feSopenharmony_ci * In Brazil, to dial numbers internally but across a certain geographical 1041767c5feSopenharmony_ci boundary, a carrier code must be explicitly dialed to say which carrier 1051767c5feSopenharmony_ci you will use to pay for the call. 1061767c5feSopenharmony_ci * In Nepal, the leading zero in national format is omitted depending on 1071767c5feSopenharmony_ci whether the originating phone is mobile or fixed-line. 1081767c5feSopenharmony_ci * In New Zealand, you need to dial the area-code (e.g. 03) even if the 1091767c5feSopenharmony_ci number is within the same area-code region as you are, unless it is 1101767c5feSopenharmony_ci "close" (something approximating city/district boundaries), in which 1111767c5feSopenharmony_ci case it shouldn’t be dialled. 1121767c5feSopenharmony_ci 1131767c5feSopenharmony_ci **Tip:** Use formatForMobileDialling to get the number a user should 1141767c5feSopenharmony_ci actually dial on their mobile phone. 1151767c5feSopenharmony_ci 1161767c5feSopenharmony_ci1. **To make a number dialable, you only need to change the prefix** 1171767c5feSopenharmony_ci 1181767c5feSopenharmony_ci In Argentina, to dial a mobile number domestically, the digits "15" need to 1191767c5feSopenharmony_ci be inserted *after* the area code but *before* the local number, and the "9" 1201767c5feSopenharmony_ci after the country code (54) needs to be removed. This transforms +54 9 2982 1211767c5feSopenharmony_ci 123456 into 02982 15 123456. 1221767c5feSopenharmony_ci 1231767c5feSopenharmony_ci1. **No prefix of a valid phone number can be a valid phone number** 1241767c5feSopenharmony_ci 1251767c5feSopenharmony_ci In some countries, it's possible to connect to a different endpoint by 1261767c5feSopenharmony_ci dialing more digits after a number. So "12345678" may not reach the same 1271767c5feSopenharmony_ci person as dialing "123456". 1281767c5feSopenharmony_ci 1291767c5feSopenharmony_ci1. **An invalid number will not reach an endpoint** 1301767c5feSopenharmony_ci 1311767c5feSopenharmony_ci In some countries, or on some phones, extra digits are thrown away. Hence, 1321767c5feSopenharmony_ci 1-800-MICROSOFT is an invalid number - but it still connects to Microsoft, 1331767c5feSopenharmony_ci since any later digits are ignored. Numbers such as "911" can be reached by 1341767c5feSopenharmony_ci dialling "911 123" in some countries: but not in others. 1351767c5feSopenharmony_ci 1361767c5feSopenharmony_ci In other countries, invalid numbers may be "fixed" by a carrier, e.g., 1371767c5feSopenharmony_ci adding a mobile token if they know it is a mobile number, such that it 1381767c5feSopenharmony_ci connects. 1391767c5feSopenharmony_ci 1401767c5feSopenharmony_ci1. **All valid phone numbers follow the ITU specifications** 1411767c5feSopenharmony_ci 1421767c5feSopenharmony_ci ITU-T specifies that a phone number cannot be longer than fifteen digits, 1431767c5feSopenharmony_ci with one to three digits reserved for the country calling code, but valid 1441767c5feSopenharmony_ci numbers in Germany have been assigned that are longer than this. 1451767c5feSopenharmony_ci 1461767c5feSopenharmony_ci1. **All valid phone numbers belong to a country** 1471767c5feSopenharmony_ci 1481767c5feSopenharmony_ci There are many "country calling codes" issued to non-geographical entities, 1491767c5feSopenharmony_ci such as satellite services, and the "800" code for [Universal International 1501767c5feSopenharmony_ci Freephone Numbers](https://en.wikipedia.org/wiki/Toll-free_telephone_number#Universal_International_Freephone_Service). 1511767c5feSopenharmony_ci 1521767c5feSopenharmony_ci1. **Phone numbers contain only digits** 1531767c5feSopenharmony_ci 1541767c5feSopenharmony_ci In Israel, certain advertising numbers start with a `*`. In New Zealand, 1551767c5feSopenharmony_ci non-urgent traffic incidents can be reported by calling `*555` from a mobile 1561767c5feSopenharmony_ci phone. Alpha characters may also be used in phone numbers, such as in 1571767c5feSopenharmony_ci `1-800-Flowers`. 1581767c5feSopenharmony_ci 1591767c5feSopenharmony_ci1. **Phone numbers are always written in ASCII** 1601767c5feSopenharmony_ci 1611767c5feSopenharmony_ci In Egypt, it is common for phone numbers to be written in native digits. 1621767c5feSopenharmony_ci 1631767c5feSopenharmony_ci1. **Phone numbers have only one prefix (area code or national destination 1641767c5feSopenharmony_ci code) at a given time** 1651767c5feSopenharmony_ci 1661767c5feSopenharmony_ci In the mid-90s in Iceland, phone numbers changed from 5 and 6 digits to 7 1671767c5feSopenharmony_ci digits. The old system had regional prefixes, but the new one doesn't. 1681767c5feSopenharmony_ci During the transition period, phone numbers could be reached by the old area 1691767c5feSopenharmony_ci code or the new 7 digit number (a different prefix). For example, a 1701767c5feSopenharmony_ci Reykjavik phone number could be dialed with `nnnnn` and `55nnnnn` inside the 1711767c5feSopenharmony_ci region, and `91-nnnnn` and `55nnnnn` from outside. 1721767c5feSopenharmony_ci 1731767c5feSopenharmony_ci **Tip:** During transition periods, make sure that both forms of a number 1741767c5feSopenharmony_ci are supported for look-up by phone number. If sending messages/dialling 1751767c5feSopenharmony_ci affected numbers, both the new and old prefix may need to be tried. 1761767c5feSopenharmony_ci Depending on the type of transition, you may need to contact affected 1771767c5feSopenharmony_ci customers and ask them to update their number. 1781767c5feSopenharmony_ci 1791767c5feSopenharmony_ci1. **A leading zero in numbers formatted for domestic usage can always be 1801767c5feSopenharmony_ci discarded when dialing from abroad** 1811767c5feSopenharmony_ci 1821767c5feSopenharmony_ci In some countries, people write the national prefix in brackets (typically 1831767c5feSopenharmony_ci `(0)`) after the country calling code to indicate that it should be 1841767c5feSopenharmony_ci discarded when dialing internationally. In Italy, since 1998, the prefix was 1851767c5feSopenharmony_ci "fixed" to the phone numbers, so that `(01) 2345` became `012345` and should 1861767c5feSopenharmony_ci be dialed (internationally) as `+39012345` (including the leading zero). 1871767c5feSopenharmony_ci 1881767c5feSopenharmony_ci **Tip:** Use the library to parse and format numbers to handle this 1891767c5feSopenharmony_ci correctly for every country. 1901767c5feSopenharmony_ci 1911767c5feSopenharmony_ci1. **The country or area code of a phone number indicates the user's location, 1921767c5feSopenharmony_ci place of residence, time-zone, or preferred language** 1931767c5feSopenharmony_ci 1941767c5feSopenharmony_ci There are many reasons for someone to have a phone number issued in a state 1951767c5feSopenharmony_ci or region other than where they reside or hold citizenship. 1961767c5feSopenharmony_ci 1971767c5feSopenharmony_ci These include, but are not limited to: 1981767c5feSopenharmony_ci * *Moving within a country*: In countries with phone number portability, 1991767c5feSopenharmony_ci you may retain your number when moving, even in some cases if it is a 2001767c5feSopenharmony_ci fixed-line number and even if it has an area code (see 2011767c5feSopenharmony_ci *[xkcd](https://xkcd.com/1129/)* for a US example.) 2021767c5feSopenharmony_ci * *Moving to another country*: Some people keep their mobile phones when 2031767c5feSopenharmony_ci they move to another country. 2041767c5feSopenharmony_ci * *Geopolitical turmoil*: Sometimes countries change their borders, cease 2051767c5feSopenharmony_ci to exist, or come into existence. 2061767c5feSopenharmony_ci * *Business, family, and friends*: A business may have many customers in a 2071767c5feSopenharmony_ci neighbouring country, or a person may have many family and friends 2081767c5feSopenharmony_ci there. 2091767c5feSopenharmony_ci * *Wanting cheaper rates*: VoIP is often cheaper than regular calls. 2101767c5feSopenharmony_ci People traveling around Europe may get a SIM card from one country and 2111767c5feSopenharmony_ci have a roaming plan. 2121767c5feSopenharmony_ci 2131767c5feSopenharmony_ci Note that geographical area codes are assigned in some countries to mobile phones. 2141767c5feSopenharmony_ci 2151767c5feSopenharmony_ci **Tip:** Programmers should not disallow users from signing up with a phone 2161767c5feSopenharmony_ci number merely because it belongs to another country. Care should be taken 2171767c5feSopenharmony_ci when calling methods such as `isValidNumberForRegion` that this is what's 2181767c5feSopenharmony_ci actually intended. If you have a phone input widget, make sure you allow 2191767c5feSopenharmony_ci numbers to be entered in international format (i.e., allow the `+` sign) so 2201767c5feSopenharmony_ci people can sign up with an international contact number. 2211767c5feSopenharmony_ci 2221767c5feSopenharmony_ci1. **The plus sign in front of phone numbers in international format is 2231767c5feSopenharmony_ci optional, or can always be replaced by `00`** 2241767c5feSopenharmony_ci 2251767c5feSopenharmony_ci The plus sign is part of the [E.164 2261767c5feSopenharmony_ci format](https://en.wikipedia.org/wiki/E.164) for international telephone 2271767c5feSopenharmony_ci numbers. It can be replaced with the [international call 2281767c5feSopenharmony_ci prefix](https://en.wikipedia.org/wiki/List_of_international_call_prefixes) 2291767c5feSopenharmony_ci when dialing internationally. Note that while `00` is a common international 2301767c5feSopenharmony_ci call prefix, this actually varies by country. 2311767c5feSopenharmony_ci 2321767c5feSopenharmony_ci In North America, which has a country calling code of `+1`, it is a common 2331767c5feSopenharmony_ci error to drop the `+` in front of the number and write it like 2341767c5feSopenharmony_ci `1-555-123-4567`. This is technically incorrect. To call this number from 2351767c5feSopenharmony_ci Japan, where the international call prefix is `010`, one may dial either `+1 2361767c5feSopenharmony_ci 555 123 4567` or `010 1 555 123 4567`. 2371767c5feSopenharmony_ci 2381767c5feSopenharmony_ci1. **Users will only store phone numbers in your product's phone number fields** 2391767c5feSopenharmony_ci 2401767c5feSopenharmony_ci Some users use their contact lists to store things like birthdays or other 2411767c5feSopenharmony_ci information. Unless a piece of user-supplied data has actually been verified 2421767c5feSopenharmony_ci to be a phone number, it should be stored as-is as entered by the user. 2431767c5feSopenharmony_ci 2441767c5feSopenharmony_ci1. **Phone numbers are numbers** 2451767c5feSopenharmony_ci 2461767c5feSopenharmony_ci Never try to store phone numbers as an int or any other kind of numeric 2471767c5feSopenharmony_ci data type. You can't do arithmetic on them, and while 007, 07 and 7 are the 2481767c5feSopenharmony_ci same number they are not necessarily the same phone number - in some 2491767c5feSopenharmony_ci countries a leading 0 is significant and forms part of the number itself 2501767c5feSopenharmony_ci (see *A leading zero in numbers formatted for domestic usage can always be 2511767c5feSopenharmony_ci discarded when dialing from abroad*). Moreover, a phone number may contain 2521767c5feSopenharmony_ci other diallable characters (see *Phone numbers contain only digits*) or an 2531767c5feSopenharmony_ci extension portion, dialled after waiting for a tone. 2541767c5feSopenharmony_ci 2551767c5feSopenharmony_ci **Tip:** Use the library to parse and format numbers to handle this 2561767c5feSopenharmony_ci correctly for every country. 2571767c5feSopenharmony_ci 2581767c5feSopenharmony_ci1. **Phone numbering plans published by governments or telecoms represent 2591767c5feSopenharmony_ci reality** 2601767c5feSopenharmony_ci 2611767c5feSopenharmony_ci National numbering plans, such as those administered by the 2621767c5feSopenharmony_ci [ITU](http://www.itu.int/oth/T0202.aspx?parent=T0202), represent the 2631767c5feSopenharmony_ci intentions of the government or telecom. These may be published before, 2641767c5feSopenharmony_ci during, or after the actual implementation of numbering plan changes in the 2651767c5feSopenharmony_ci real world. The actual date on which a phone number range becomes active may 2661767c5feSopenharmony_ci not always adhere to official announcements. 2671767c5feSopenharmony_ci 2681767c5feSopenharmony_ci1. **Nobody voice calls M2M sim numbers** 2691767c5feSopenharmony_ci 2701767c5feSopenharmony_ci M2M sim cards are for machine-to-machine communication and are up to 2711767c5feSopenharmony_ci 15 characters long. Typically they are used for data and SMS messages, 2721767c5feSopenharmony_ci however there are cases in which someone may voice-call an M2M sim. 2731767c5feSopenharmony_ci One example is for in-home & roaming telecare/medical alarms, 2741767c5feSopenharmony_ci in the event of an alarm activation then automated voice messages can be 2751767c5feSopenharmony_ci played on the device via telephony APIs, or a human may call the device 2761767c5feSopenharmony_ci directly (potentially also via a telephony API). 277