Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Jules2010

macrumors member
Original poster
I've arrived at the code to do either limiting the length OR acceptable characters, but how do I do both for the same field.

Heres my code
Code:
- (BOOL)textField:(UITextField *)textField 
    shouldChangeCharactersInRange:(NSRange)range 
    replacementString:(NSString *)string
{
    NSString *newString = [textField.text 
        stringByReplacingCharactersInRange:range withString:string];
    return !([newString length] > 3);
}

And

Code:
(NSRange)range replacementString:(NSString *)string
{
    NSCharacterSet *nonNumberSet = [[NSCharacterSet 
        characterSetWithCharactersInString:@"0123456789."] invertedSet];
    return ([string stringByTrimmingCharactersInSet:nonNumberSet].length > 0);
}

Thanks in advance
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.