- (void)textFieldDidEndEditing:(UITextField *)textField
{
NSString *tempstr=(NSMutableString *)textField.text;
NSError *error;
//用正则表达式判断输入是否是数字,三位位数不超过三位
NSRegularExpression *regex = [NSRegularExpressionregularExpressionWithPattern:@"^[0-9]+(.[0-9]{1,3})?$"options:0 error:&error];
if (regex != nil) {
NSTextCheckingResult *firstMatch = [regex firstMatchInString:tempstr options:0 range:NSMakeRange(0, [tempstr length])];
if (firstMatch) {
//匹配
ob.wcsl = (NSMutableString *)textField.text;
}
else
{
//不匹配
UIAlertView *alert=[[UIAlertViewalloc] initWithTitle:@"输入了非法字符或小数位数超过了三位" message:nil delegate:nilcancelButtonTitle:@"ok"otherButtonTitles:nil];
[alert show];
[alert release];
}
}
}