0

In my app, i have some text fields for..

  • Phone number
  • Date
  • Currency
  • Email

I want to get the input value as NSString from the text field, and want to make sure that it satisfies the required scenario. That is, the phone number field should contains digits and + symbol only, Date in the form of dd/mm/yyyy, Currency may contain $ symbol and email should satisfy a valid email format.

How can i do this in Objective C?

1 Answer 1

1
  1. For phone number you can set your textfield.keyboardType = UIKeyboardTypePhonePad;

  2. For Date you can use UIDatePicker - http://developer.apple.com/library/ios/#documentation/uikit/reference/UIDatePicker_Class/Reference/UIDatePicker.html

  3. Currency, you can set your textfield.keyboardType = UIKeyboardTypeNumbersAndPunctuation;

  4. Email: you can set your textfield.keyboardType =UIKeyboardTypeEmailAddress

but still you will have to write the code for proper validation after user input as above will help you to show proper keyboard but still user can enter incorrect values...

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your answer. Even though we can set the keyboard type, the user also provided with the "copy" & "paste" option in the text field. That time, i need to validate the input string. So, for that, what should i use?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.