标签:
-(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;
}
}
标签:
原文地址:http://my.oschina.net/u/1466119/blog/395272