因为各个公司的需求不同,当时我也是很麻烦才找到了这些验证的东西,今天我把他整理一下,希望以后有人再用的时候,可以容易一点,一言不合,直接上代码
一、身份证的验证
+ (BOOL)validateIDCardNumber:(NSString *)value {
value = [value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSInteger length =0;
if (!value) {
return NO;
}else {
length = value.length;
if (length !=15 && length !=18) {
return NO;
}
}
// 省份代码
NSArray *areasArray =@[@"11",@"12", @"13",@"14", @"15",@"21", @"22",@"23", @"31",@"32", @"33",@"34", @"35",@"36", @"37",@"41", @"42",@"43", @"44",@"45", @"46",@"50", @"51",@"52", @"53",@"54", @"61",@"62", @"63",@"64", @"65",@"71", @"81",@"82", @"91"];
NSString *valueStart2 = [value substringToIndex:2];
BOOL areaFlag =NO;
for (NSString *areaCode in areasArray) {
if ([areaCode isEqualToString:valueStart2]) {
areaFlag =YES;
break;
}
}
if (!areaFlag) {
return false;
}
NSRegularExpression * regularExpression;
NSUInteger numberofMatch;
NSInteger year = 0;
if (length==15) {
year = [value substringWithRange:NSMakeRange(6,2)].intValue +1900;