… and tips on how to use libphonenumber.
Given how ubiquitous phone numbers are and how long they’ve been around, it’s surprising how many false assumptions programmers continue to make about them.
1.An individual has a phone numberSome people do not own phones, or do not wish to provide you with their telephone number when asked. Do not require a user to provide a phone number unless it is essential, and whenever possible try and provide a fallback to accommodate these users.2.An individual has only one phone numberObviously, this isn’t necessarily true.3.A phone number uniquely identifies an individualIt wasn’t even that long ago that mobile phones didn’t exist, and it was common for an entire household to share one fixed-line telephone number. In some parts of the world, this is still true, and relatives (or even friends) share a single phone number. Many phone services (especially for businesses) allow multiple inbound calls to or outbound calls from the same phone number.4.Phone numbers cannot be re-usedOld phone numbers are recycled and get reassigned to other people.5.Phone numbers that are valid today will always be valid. Phone numbers of a certain type today (e.g., mobile) will never be reassigned to another type.A phone number which connects today may be disconnected tomorrow. A number which is free to call today may cost money to call tomorrow. The phone company may decide to expand the range of available phone numbers by inserting a digit into an existing number.Tip: Don’t store properties for a phone number such as validity or type. Check this information again from the library when you need it.6.Each country calling code corresponds to exactly one countryThe USA, Canada, and several Caribbean islands share the country calling code +1. Russia and Kazakhstan share +7. These are not the only examples<img src="https://link.juejin.cn/?target=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FToll-free_telephone_number%23Universal_International_Freephone_Service “https://en.wikipedia.org/wiki/Toll-free_telephone_number#Universal_International_Freephone_Service”). Some may be dialable only if the caller is a subscriber to a particular telecom company.9.You can send a text message to any phone numberA lot of people still only have a fixed-line telephone, which typically cannot send or receive text messages.Tip: Whenever possible, try and accommodate these users by calling them with a voice message or voice prompts. Alternatively, if your service requires sending text messages, verify that the number can receive text messages after the user provides i