-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
return [self validateNumberByRegExp:string];
}
- (BOOL)validateNumberByRegExp:(NSString *)string {
BOOL isValid = YES;
NSUInteger len = string.length;
if (len > 0) {
NSString *numberRegex = @"^[0-9]*$";
NSPredicate *numberPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", numberRegex];
isValid = [numberPredicate evaluateWithObject:string];
}
return isValid;
}