Phone Number Auto Spacing like AddressBook on iPhone
-
16-09-2019 - |
Question
I want to be able to replicate what the AddressBook does in Contacts app and Phone app when entering a phone number in both the keypad on the Phone app and adding a contact.
I know I could do it checking each time a character is entered into the UITextField but there are hundreds of number formats out there and it would take me forever to code it all.
Is there any API to this I can use or any known open source code I could use at all?
Solution
The UIPhoneFormats.plist contains predefined phone formats for each locale. You'll need to write code to subsitute your input string into these string masks. I had to do something similar, and I shared the results I got here: http://the-lost-beauty.blogspot.com/2010/01/locale-sensitive-phone-number.html
OTHER TIPS
You hit the nail on the head - check the characters typed each time.