I\'m trying to convert a string of numbers, entered by the user, into a sexy string like Phone.app on the iPhone. Here is the code I\'m using, which doesn\'t work (no specia
I think your issue is that NSNumberFormatter
does not support brackets, spaces or dashes. I tried to implement the same method as you and it failed silently and just output unformatted text.
The general problem here is that the iPhone SDK doesn't provide a method to format phone numbers in a locale dependent way.
I have raised bugs with Apple for the following (two of these were duplicates of known issues so I've included Apple's original bug # for those):
#6933244 - Need iPhone SDK interface to format text as locale dependent phone number
#5847381 - UIControl does not support a setFormatter method
#6024985 - Overridden UITextField drawTextInRect method is never called
In an ideal world Apple would provide an NSPhoneNumberFormatter
, and you would call setFormatter
on your UIControl
so it displayed text
in a nice pretty way. Unfortunately that doesn't exist on the iPhone.