Reputation: 450
I have a problem trying to get the country code from phone number captured from personal address book. My intention is, for instance, in the following options:
00 34 633 445 433
+34 633 445 433
Get the 34 international code in one variable, and the phone number without the international code in another. I have investigated possible auxiliary libs or NSString apis but I didn't find a solution.
Thanks
Upvotes: 2
Views: 2890
Reputation: 299623
This is non-trivial (or at least quite tedious). Country codes can be of various lengths (1-3 digits), so you have to have a complete list of them in your code to work this out. These values do change sometimes, which can require changes to your code. In most cases, though, the legal country codes themselves don't change; just which country they refer to.
The table you need is ITU-T E.164. The Wikipedia page can also be handy.
If you want to handle "00" as though it were "+", then you'll need to code that yourself as well.
Just in case you wind up going the other direction (turning a country code into a country), keep in mind that there are currently a few ambiguous cases. The most commonly impacting is +1, which is all of NANP. That's the US, Canada, and much (but not all) of the Caribbean. Sometimes people think it means "the US." The other big ambiguity is Russia and Kazakhstan, which are both +7. There are other minor confusions in there, mostly due to territorial disputes, but those are the two big top-level ambiguities.
Upvotes: 4