开发者

Formatting phone numbers on iOS

Is there a way to format the phone numbers? For e.g. +11开发者_Go百科234567890 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).


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜