// 限制输入非数字和.
for(NSIntegerindex =0; index < string.length; index++) {
unicharc = [stringcharacterAtIndex:index];
if(c <48&& c !=46) { // 46是.
returnNO;
}
if(c >57) {
returnNO;
}
}
NSRangepointRange = [textField.textrangeOfString:@"."];
if(pointRange.location!=NSNotFound) {
// 有小数点了
if([stringisEqualToString:@"."]) {
// 不允许再输入小数点
returnNO;
}
NSArray*list = [textField.textcomponentsSeparatedByString:@"."];
if(list.count==2) {
NSString*str = list.lastObject;
if(str.length>=2&& ![stringisEqualToString:@""]) {
// 不能超过两位小数,退格键
returnNO;
}
}
}