iphonevibermobile-country-code

How to determine if a phone number (with country calling code) is equal to another (whithout country calling code)


I am working on an application like 'Viber' for iPhone ( http://www.viber.com/ ).

I need to use the user phone number as ID in my database.

When the user launch the application, I need to determine which contacts use the same application. I can get contacts phone number with ios API.

But this scenario is problematic when considering country calling codes ( http://en.wikipedia.org/wiki/List_of_country_calling_codes ) :

When "registering", the USER A type his phone number without country calling code. The USER A is in the contact list of USER B, but without the country calling code.

For instance, in France : +33 x xx xx xx xx is refering to the same phone that 0x xx xx xx xx

Is there a simple way to resolve this problem ?


Solution

  • There is no easy way to convert from a local format to E.164 format. The problem is that every countries local mobile format varies, so you can't have one set of rules for all countries. You have to find out what formats a countries local mobile carrier supports.

    If you have to support multiple countries then you may be base it on the MCC/MNC returned from the iphone. I have yet to find a list of what the local formats are supported in what countries. It also doesn't get around the problem of a roaming phone where the number is in a local format.

    If you have to deal with multiple countries then you are going to have problems with countries like Australia, who support local number formats that make converting them to E.164 format almost impossible without further information....

    See this Question which is basically the same question that you have.

    I would recommend that all your users use E.164 format for storing all there phone numbers. If you have to support a conversion, only support the country formats you have to deal with. Make sure you investigate all the formats that country supports.

    You can try to a generic one like in the question above tries to use, but it will not work for all number formats.

    In the PBX software that I work on, we use a rules based engine that the customer can configure for there environment and we try to pre-populate for the countries that we sell into.