NSString判断纯数字

//判断是否为整形:

- (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:insertValue.text] || ![self isPureFloat:insertValue.text])
    {
        resultLabel.textColor = [UIColor redColor];
        resultLabel.text = @"警告:含非法字符,请输入纯数字!";
        return;
    }

 

posted @ 2014-10-21 16:10  PressII...  阅读(402)  评论(0编辑  收藏  举报