views:

144

answers:

1

Hi All,

First of all I wish you a happy new year.

Coming to my question, is there a way to format the phone numbers? For e.g. +11234567890 to +1(123) 456-789. And also is it possible to separate ISD and STD codes in the phone number itself? Since apple is doing the same in IPhone's address book and as well as Mobile application, I believe that there is way to the same (but no idea how to do).

Any help is appreciated.

Regards, Prathap.

A: 

You want NSDataFormatter and probably NSNumberFormatter. Both are classes designed to handle just this type of problem with minimum fuss.

If you handle a lot of phone numbers you might want to go ahead and write a dedicated formatting subclass just for phone numbers. I used to have one that would return properly localized phone numbers e.g. formats for North America vs Europe vs Asia etc depending on the location set for the device.

Phone numbers are one of those common pieces of data whose handling grows surprisingly complex very quickly especially when you start throwing in international variations and various types of extensions like calling cards or voice tree controls.

TechZen
I'm using the formatters to format the phone numbers. But my question is, is there a way to this with minimum pain? I just wanna format the all country phone numbers by separating ISD and STD codes. So does apple provides a mechanism to do this? Is there any data base or .plist file, which is contains all this ISD and STD info?
prathumca
No, the API has no dedicated phone# handling class. Like I said, phone numbers are one of those things that look simple but that quickly get complex and specialized. It's one of those things that needs to be customized for each app.
TechZen