Is there any support for auto-formatting phone numbers as they're being entered into a text field, the way that the Contacts utility does?
I have a text field that's using a phone number keyboard, and if the user is trying to enter an international number or even an 11 digit number, it's not very user-friendly with no formatting.
Since there is no standard support for this, the easiest would be override the input of the textField by attaching an listener to the 'change' event, then doing your formatting (like adding a space every 3 chars etc.) and then passing the altered input into the textField.
To retrieve the text you could go two ways. Either make a function that strips the textField of the formatting, or store the raw input value somewhere. The first option is probably safer.
Hope this helps you out.
Thanks Angus, this is exactly what I'm doing at the moment. I was just looking at how the phone number text field works in the Contacts utility, and for international numbers, the number of different cases to handle is somewhat overwhelming.
I was really hoping there'd be existing support for formatting phone numbers, since that seems like a pretty central part of iPhone development, but no luck, I guess.
Think you can help? Login to answer this question!