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?
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.
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 .
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.
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.
See https://github.com/rmaddy/RMPhoneFormat for an iOS specific solution.
Try this Google solution - https://github.com/me2day/libPhoneNumber-iOS They have ports for C++, Java, Objective-C and others.
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