#pragma mark- UITextFieldDelegate
//在这个代理方法
//限定9位、小数点后两位、开头只能输入一个0、只能有一位小数点
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
NSString *toString = [textField.text stringByReplacingCharactersInRange:range withString:string];
if (toString.length > 0) {
//NSString *stringRegex = @"(\\+|\\-)?(([0]|(0[.]\\d{0,2}))|([1-9]\\d{0,4}(([.]\\d{0,2})?)))?";//(带正负号的)
NSString *stringRegex = @"(([0]|(0[.]\\d{0,2}))|([1-9]\\d{0,8}(([.]\\d{0,2})?)))?";//一般格式 d{0,8} 控制位数
NSPredicate *money = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", stringRegex];
BOOL flag = [money evaluateWithObject:toString];
if (!flag) return NO;
}
return YES;
}