-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
NSInteger existedLength = textField.text.length;
NSInteger selectedLength = range.length;
NSInteger replaceLength = string.length;
if (existedLength - selectedLength + replaceLength < 7) {
if ([string length]>0)
{
unichar single=[string characterAtIndex:0];//当前输入的字符
if ((single >=‘0‘ && single<=‘9‘))//数据格式正确
{
return YES;
}else{
return NO;
}
}else{
return YES;
}
}else{
return NO;
}
}
时间: 2025-01-06 23:19:54