设置textFiled的代理
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string; {
NSString * newStr = [textField.text stringByReplacingCharactersInRange:range withString:string];
NSString * expression = @"^[0-9]*((\\.|,)[0-9]{0,2})?$";
NSRegularExpression * reguslar = [NSRegularExpression regularExpressionWithPattern:expression options:NSRegularExpressionAllowCommentsAndWhitespace error:nil];
NSUInteger numberOfMatches = [reguslar numberOfMatchesInString:newStr options:NSMatchingReportProgress range:NSMakeRange(0, newStr.length)];
returnnumberOfMatches!=0;
}