验证字符串是否是纯数字

- (BOOL)validateNumber:(NSString*)number {

BOOL res =YES;

NSCharacterSet* tmpSet = [NSCharacterSetcharacterSetWithCharactersInString:@"0123456789"];

inti =0;

while(i < number.length) {

NSString* string = [numbersubstringWithRange:NSMakeRange(i,1)];

NSRangerange = [stringrangeOfCharacterFromSet:tmpSet];

if(range.length==0) {

res =NO;

break;

}

i++;

}

returnres;

}

你可能感兴趣的:(验证字符串是否是纯数字)