Here's the situation: users of my app are going to create their account using their phone number only (like WhatsApp for example). So no username, password or anything like that. I'll be storing those phone numbers in my database after verification, so I know all the stored numbers will be in one specific format.
The tricky part, however, is that I want my app to look through my users' contacts to see if their contacts have an account on my app's server. In theory, I just wanted the app to check the phone number and see if it exists in my database, because I'm pretty sure the phone number is the only (unique) property of a contact my app will have access to (please correct me if I'm wrong).
The thing I'm afraid of is that every smartphone owner stores the phone number of a contact in their own way. What I mean by this is that for example, one person might store the phone number of a contact in a 'clean way', with the country code and area code and everything else that should be in a phone number, like this: +1 xxx xxx xxxx (I'm from The Netherlands and I'm just guessing, so my apologies to all the American readers if this is NOT what an American phone number looks like). Some other person might store the phone number of his contact the 'quick way', without any country codes or area codes, like this: xxx xxx xxxx (no country code) or even xxx xxxx (no area code).
This would already be an issue in one country (the USA for example), not to mention the situation in which someone has contacts from other countries (with their own area code rules) in his phone. The contact in a person's contact list still might be using my app with their phone number, but if that person stored his contact's phone number in the 'quick way' my app wouldn't be able to find it in the database. Right now, I'm either looking for an alternate unique value of a contact which I can also store in my database to use that as the identifier instead (I highly doubt that exists though), or preferably a way to make the app search a little more dynamically, so that it would identify a matching phone number even if the number stored in the contacts list isn't identical to the phone number stored in my database.
Rather than some technical advice, I'd rather hear from someone who knows a thing or two about phone numbers around the world. For instance: would it be smart to just search for the last 8 digits of a contact's phone number instead, or would that be risky in terms of a possible duplicate phone number elsewhere in the world? Just wondering what the safest way is to go about this...
By the way: the app I'm building is written in Swift 3, and I'll be accessing the contacts of a user through Apple's Contacts Framework.
Unique codes are tricky - especially when based on real-world data (which is generally pretty noisy and with more exceptions that you can think of).
I agree that "last 8 digits" would be very risky. Instead what I'd do is figure out (or guess) what country the user comes from, and always store that with the phone number (even if the user doesn't choose to display it).
So lets say that if they have an address with a country - then use that country's country-code. If they don't, then have a "default" country (USA is oft-used, though I really hate that (I'm from Australia).
Be aware you will still get errors and exceptions, but it means you can make an educated guess if 9123 4567 is the same as (+61) 9123 4567.
Also be aware of things like: