美文网首页
金额输入框输入限制

金额输入框输入限制

作者: 然亦伞 | 来源:发表于2016-06-14 16:50 被阅读187次

- (BOOL)validateWtihRegex:(NSString *)regexString {

NSPredicate *regex = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regexString];

return [regex evaluateWithObject:self];

}

#pragma mark - UITextFieldDelegate

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {

NSString *currentText = textField.text;

NSString *newText = [currentText stringByReplacingCharactersInRange:range withString:string];

if ([newText isEqualToString:@"."] || [newText isEqualToString:@"00"]) {

return NO;

}

return [newText validateWtihRegex:@"^(0?|[1-9][0-9]*)(\\.[0-9]{0,2})?$"];

}

相关文章

网友评论

      本文标题:金额输入框输入限制

      本文链接:https://www.haomeiwen.com/subject/mseudttx.html