- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSString *text = [textField.text stringByReplacingCharactersInRange:range withString:string]; NSString *regexStr = @"^\\d{0,3}$"; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self matches %@", regexStr]; if([predicate evaluateWithObject:text] && [text integerValue] <= 100){ return YES; } return NO; }