I am receiving phone numbers from a mobile device, format varies from international format or not.
Scenario (ZA formats just for the example) :
Registered numbers in database are always international format : +27827177982
Numbers I receive can vary e.g. +27827177982
= 27827177982
= 0827177982
- international prefix for number is +27
How do I match it to the international format even though I don't receive the international format???
Keep in mind :
I can't do conversion just for 1 region.
Is there a simple way of comparing mobile phone numbers for all regions?
Prefixes ranges in amount of chars reference : http://en.wikipedia.org/wiki/List_of_country_calling_codes
My ideas :
Compare the last 9 characters of the number, this will rule out the region prefix... but does every region only have '9 characters excluding the prefix'?
Loop through the database comparing the phone numbers a couple a times e.g. check for last 9 numbers - if no match - check for last 10 etc. (But can cause unwanted matches)
Any help would greatly be appreciated
You may want to look into using a library for this. For example, Google's libphonenumber library with a C# port being here. In particular, these two methods may be worth looking into (emphasis mine)
isNumberMatch - gets a confidence level on whether two numbers could be the same.
getExampleNumber/getExampleNumberByType - provides valid example numbers for all countries/regions, with the option of specifying which type of example phone number is needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With