控制输入电话号码
//控制输入电话号码 + (BOOL)validateNumber:(NSString*)number range:(NSRange)range{ BOOL res = YES; NSCharacterSet *tmpSet; if (range.location == 0) { tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"1"]; } else if(range.location == 1) { tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"34578"]; } else { tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"]; } int i = 0; while (i < number.length) { NSString * string = [number substringWithRange:NSMakeRange(i, 1)]; NSRange tmpRange = [string rangeOfCharacterFromSet:tmpSet]; if (tmpRange.length == 0) { res = NO; break; } else { if (range.location >= 11) { res = NO; } else { res = YES; } } i++; } return res; }