开发者

Text validation in objective c

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 sa开发者_StackOverflow中文版tisfies 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. 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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜