i need to enter mobile number in a text field.
i need to display mobile number like this format 123-456-7890.
for eg: 1234567890 is my mobile number,while am entering this mobile number in text field,
for first 3 digits i need to place -,after 3 digits again i need to place -.
if i enter 123 then automatically place – in text field,after 456 place ,no need of placing for further 4 digits.
similar to displaying text in currency format.
but while getting text from that text field i need to get mobile number no need of – like 1234567890,not 123-456-7890.
i think my question is quite clear now,let me add comment if is not.
Thank u in advance.
Just to clarify: As a user enters a phone number into a UITextField, you would like it to automatically insert dashes in the proper places.
The answer is in using the UITextFieldDelegate protocol.
1) Set your controller object as a delegate for the UITextField.
2) You’ll find the following method in the protocol:
This method is called every time a character change occurs in the text field.
3) How robust you want your implementation to be is up to you. You could simply do a count of the current characters and insert dashes after 3 and 6 characters. It would be wise to also reject any non-numeric characters.
Here is a sample implementation. We basically take over the field editing manually – Inserting dashes after the appropriate string lengths and making sure the user can only enter numbers: