how do you put in user validation?

Discussion in 'iOS Programming' started by ideviant, Jul 8, 2011.

  1. ideviant macrumors newbie

    Jun 23, 2011
    i'm currently doing a application that need user to put in numbers like (mins:sec, 10.3 and whole number) instead of putting in text and the wrong information or leaving the textField blank.
    how do i put in the user validation for all of those?
    thanks in advance. :)
  2. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    On MacOS X there is an extensive toolkit for this. On iOS, not so much.

    Look at the UITextField Delegate protocol. Particularly:

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;   // return NO to not change text
    If you're clever you might create a simple class that does the validation that you need and which can be called from that delegate callback.
  3. ideviant thread starter macrumors newbie

    Jun 23, 2011
    but i'm doing this on a iOS, is there a way for me to do it in the iOS itself?
  4. jiminaus macrumors 65816


    Dec 16, 2010
    I think the best user experience in these kind of scenarios is not to user a general text field, but to develop specific input controls. For example, the don't use a text field for mins:secs, use a custom UI like the timer function of the standard clock app. For number entry, use a numeric keyboard, so only numbers and points can be entered.
  5. ideviant thread starter macrumors newbie

    Jun 23, 2011
    hi, thanks for the help,
    can you teach me how do i do the timer and numeric keyboard out?
    thanks in advance.
  6. forum user macrumors regular

    Aug 28, 2008
    Well, see, we don't teach here. Programmers get twitchy when they are asked to "teach". You probably meant to say; "please give me a hint and I will search the details for myself", or similar ;)

    The minutes is not a obvious one: use a UIDatePicker and set the date and the time format as needed.

    The number pad is a kind of keyboard. Look in interface builder when you define the text field and one of the options for the text field is the type of keyboard shown.

    The numbers entered by the user check with a set of if/then/elses and react to any undesired input.

    - Olaf
  7. ideviant thread starter macrumors newbie

    Jun 23, 2011
    so sorry about that, i will try it out later on, if there's other problem, can i ask her advice on how to codes should be done as well?

  8. ideviant thread starter macrumors newbie

    Jun 23, 2011

    i have solved the problem of the keyboard, but i'm unable to make user validation and the Picker. can anybody give me any hint on how i can improve it?

    thanks in advance.


Share This Page