开发者

Text validation in objective c

开发者 https://www.devze.com 2023-01-26 20:28 出处:网络
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中文版

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

精彩评论

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