//判斷是否為整形:
- (BOOL)isPureInt:(NSString*)string{
NSScanner* scan = [NSScanner scannerWithString:string];
int val;
return[scan scanInt:&val] && [scan isAtEnd];
}
//判斷是否為浮點形:
- (BOOL)isPureFloat:(NSString*)string{
NSScanner* scan = [NSScanner scannerWithString:string];
float val;
return[scan scanFloat:&val] && [scan isAtEnd];
}
if( ![self isPureInt:textField.text] || ![self isPureFloat:textField.text]){
textField.textColor = [UIColor redColor];
textField.text = @"警告:含非法字符,請輸入純數字!";
return;
}else{
textField.textColor = [UIColor blackColor];
if ([textField.text integerValue]>self.moneyT) {
[SMAlertView showAlert:[NSString stringWithFormat:@"退款金額不能超過錢袋的總金額%ld,請重新輸入",(long)self.moneyT]];
textField.text=nil;
}else{
self.money = textField.text;
}
}