iphone:Validating NSTextField / NSFormatter

Discussion in 'Mac Programming' started by bymartin, Apr 7, 2008.

  1. bymartin macrumors newbie

    Jul 14, 2003

    I have a UITextField that I'd like to validate the input as currency. I looked into using NSFormatter and was able to create one, but the iphone library does not appear to have the setFormatter method to associate the NSNumberFormatter with the textfield.

    Does anyone know how to make this association?

    Maybe I should use NSCharacterSet instead and just check to make sure my input is part of a custom set (0-9 and .) using characterIsMember?
  2. springframework macrumors member

    Mar 31, 2008
    If you implement the UITextFieldDelegate and set the textfield.delegate = ...

    then inside the delegate functions you can do any formatting/error processing/screen updates/... that you want.

    -(BOOL)textFieldShouldReturn(UITextField *)textField{
    return YES;
    return NO;

    there are other functions that can be defined for UITextFieldDelegate
  3. bymartin thread starter macrumors newbie

    Jul 14, 2003
    Thanks...I already have that part. My question was how to use NSNumberFormatter - but I can do it manually. I was just trying to figure out how to use this convenience class rather than coding it myself.
  4. bymartin thread starter macrumors newbie

    Jul 14, 2003
    I have it working...I just made a custom NSCharacterSet and then parse my string and check for membership of each unichar. If it's not a member, I can return NO, display an alert, and have the user enter good input.
  5. Sbrocket macrumors 65816


    Jun 3, 2007
    You might want to file a bug report (http://bugreporter.apple.com/) just to let engineering be aware that it's not there for UIControl. It could be an intentional decision or it could just be something that got left out, but no one will ever review it if a bug isn't filed. Radar bugs are how the engineers work.
  6. bymartin thread starter macrumors newbie

    Jul 14, 2003

Share This Page