金额输入框输入限制

2016-06-14  本文已影响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})?$"];

}

上一篇下一篇

猜你喜欢

热点阅读