Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Localized phone number formatting

I've looked into NSFormatter, NSNumberFormatter, and the other formatting classes, but can't find a build into solution. I need to format phone numbers depending on the country code.

For instance, for US, I get a string such as +16313938888 which I need to format to look like +1(631)393-8888. The problem is I need to do this for all formats. Netherlands, I receive a string +31641234567 which will be +31(6)41 23 45 67 (something like that).

Hardcoding for 200+ countries is too tedious and I really don't know all the format rules. Is there something in the docs I'm overlooking or does anyone know of an open source class that manages this?

like image 836
Chris Avatar asked Sep 13 '12 13:09

Chris


People also ask

How do you write a local phone number?

For landline telephone numbers, write the 2-digit area code followed by a non-breaking space. Then write the rest of the number in 2 chunks of 4 digits. Write mobile telephone numbers in 1 chunk of 4 digits and then 2 chunks of 3 digits.

How do you format a phone number professionally?

You should provide the complete number, including the country code with no use of special characters or spaces. Just the number. For example, a phone number like +1-555-555-1212 should be formatted as 15555551212 .

What is phone number correct format?

Check whether the phone number is in the right format, which is + (country code) (region code, if applicable) phone number. You must use this format for both domestic and international phone numbers.

When using +44 do I drop the 0?

Calling these numbers from outside the UK Depending on the service provider within the country of origin, you may be able to call an 08 or 03 number from outside the UK. To do so, you will need to drop the 0 from the start of the number and instead dial +44 followed by the rest of the number.


2 Answers

See https://github.com/rmaddy/RMPhoneFormat for an iOS specific solution.

like image 110
rmaddy Avatar answered Oct 21 '22 17:10

rmaddy


Try this Google solution - https://github.com/me2day/libPhoneNumber-iOS They have ports for C++, Java, Objective-C and others.

like image 44
fir Avatar answered Oct 21 '22 18:10

fir