_TextField.text 输入框内容, string 为输入新内容
//1. 判断某字符串是否是数字
- (BOOL)isPureInt:(NSString *)string{
NSScanner* scan = [NSScannerscannerWithString:string];
int val;
return [scanscanInt:&val] && [scan isAtEnd];
}
//时时获取输入框输入的新内容 return NO:输入内容清空 return YES:输入内容不清空, string 输入内容 ,range输入的范围
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
if ([selfisPureInt:string]) {
if ([selfjudgeFirstChar:string]) {
returnNO;
}else{
NSString *all_PRice = [NSStringstringWithFormat:@"%@%@",_TextField.text,string];
[selfcompare:all_price];
returnYES;
}
}else{
[selfgoToTelephone:@"你输入的内容并非数字请重新输入"];
}
returnNO;
}
//判断输入内容首位是否是数字
-(BOOL)judgeFirstChar:(NSString*)string{
if (_TextField.text.length==0&&[stringisEqualToString:@"0"]) {
returnYES;
}else{
returnNO;
}
}
新闻热点
疑难解答