//ID Number Validation 1900+/2000+ the regular expression of the year date has been modified, it seems to be right, if a friend found the error to be able to give hints//The return yes bit indicates the format is correct, otherwise the error-(BOOL) Idcardauth: (NSString *) value{//Stringbytrimmingcharactersinset: Removing special characters from a string//[Nscharacterset Whitespaceandnewlinecharacterset] Space//Customize the special characters to be removed//nscharacterset *set = [Nscharacterset charactersetwithcharactersinstring:@ "@/:; () ¥""", []{}#%-*+=_\\|~ <> $€^· ' @# $%^&* () _+ ' \ "";Value =[value Stringbytrimmingcharactersinset:[nscharacterset Whitespaceandnewlinecharacterset]]; Nsinteger length=0; if(!value) { returnNO; }Else{length=value.length; if(Length! = the&& Length! = -) { returnNO; } } //Province CodeNsarray *areasarray [Email protected][@" One",@" A",@" -",@" -",@" the",@" +",@" A",@" at",@" to",@" +",@" -",@" the",@" *",@" $",@"Panax Notoginseng",@" A",@" the",@" +",@" -",@" $",@" $",@" -",@"Wuyi",@" the",@" -",@" Wu",@" A",@" +",@" the",@" -",@" $",@" in",@"Bayi",@" the",@" the"]; NSString*valuestart2 = [Value substringtoindex:2]; BOOL Areaflag=NO; for(NSString *areacodeinchAreasarray) { if([AreaCode Isequaltostring:valuestart2]) {Areaflag=YES; Break; } } if(!Areaflag) { return false; } //encoding of the birthday partNsregularexpression *RegularExpression; Nsuinteger Numberofmatch; Nsinteger Year=0; Switch(length) { Case the: Year= [Value Substringwithrange:nsmakerange (8,2)].intvalue +1900; if(Year% -==0|| (Year% -!=0&& Year%4==0) ) {RegularExpression= [[Nsregularexpression alloc]initwithpattern:@"^[1-9][0-9]{5}[0-9]{2} ((01|03|05|07|08|10|12) (0[1-9]|[ 1-2][0-9]|3[0-1]) | (04|06|09|11) (0[1-9]| [1-2] [0-9]|30] |02 (0[1-9]|[ 1-2][0-9])) [0-9]{3}$"Options:ns Regularexpressioncaseinsensitive Error:nil];//test the legality of birth date }Else{regularexpression= [[Nsregularexpression alloc]initwithpattern:@"^[1-9][0-9]{5}[0-9]{2} ((01|03|05|07|08|10|12) (0[1-9]|[ 1-2][0-9]|3[0-1]) | (04|06|09|11) (0[1-9]| [1-2] [0-9]|30) |02 (0[1-9]|1[0-9]|2[0-8])) [0-9]{3}$"Options:ns Regularexpressioncaseinsensitive Error:nil];//test the legality of birth date } //Numberofmatch: Number of strings to matchNumberofmatch =[RegularExpression Numberofmatchesinstring:value Options:nsmatchingreportprogress Range:nsmakerange (0, Value.length)]; if(Numberofmatch >0) { returnYES; }Else { returnNO; } Case -: Year= [Value Substringwithrange:nsmakerange (6,4)].intvalue; if(Year% -==0|| (Year% -!=0&& Year%4==0)) { //the original @ "^[1-9][0-9]{5}19[0-9]{2} ((01|03|05|07|08|10|12) (0[1-9]|[ 1-2][0-9]|3[0-1]) | (04|06|09|11) (0[1-9]| [1-2] [0-9]|30] |02 (0[1-9]|[ 1-2][0-9])) [0-9]{3}[0-9xx]$]RegularExpression = [[Nsregularexpression alloc]initwithpattern:@"^[1-9][0-9]{5} (19|20) [0-9]{2} ((01|03|05|07|08|10|12) (0[1-9]|[ 1-2][0-9]|3[0-1]) | (04|06|09|11) (0[1-9]| [1-2] [0-9]|30] |02 (0[1-9]|[ 1-2][0-9])) [0-9]{3}[0-9xx]$"Options:ns Regularexpressioncaseinsensitive Error:nil];//test the legality of birth date }Else{regularexpression= [[Nsregularexpression alloc]initwithpattern:@"^[1-9][0-9]{5} (19|20) [0-9]{2} ((01|03|05|07|08|10|12) (0[1-9]|[ 1-2][0-9]|3[0-1]) | (04|06|09|11) (0[1-9]| [1-2] [0-9]|30) |02 (0[1-9]|1[0-9]|2[0-8])) [0-9]{3}[0-9xx]$"Options:ns Regularexpressioncaseinsensitive Error:nil];//test the legality of birth date} numberofmatch=[RegularExpression Numberofmatchesinstring:value Options:nsmatchingreportprogress Range:nsmakerange (0, Value.length)]; //Verifying the check digit if(Numberofmatch >0) { intS = ([Value Substringwithrange:nsmakerange (0,1)].intvalue + [value substringwithrange:nsmakerange (Ten,1)].intvalue) *7+ ([Value Substringwithrange:nsmakerange (1,1)].intvalue + [value substringwithrange:nsmakerange ( One,1)].intvalue) *9+ ([Value Substringwithrange:nsmakerange (2,1)].intvalue + [value substringwithrange:nsmakerange ( A,1)].intvalue) *Ten+ ([Value Substringwithrange:nsmakerange (3,1)].intvalue + [value substringwithrange:nsmakerange ( -,1)].intvalue) *5+ ([Value Substringwithrange:nsmakerange (4,1)].intvalue + [value substringwithrange:nsmakerange ( -,1)].intvalue) *8+ ([Value Substringwithrange:nsmakerange (5,1)].intvalue + [value substringwithrange:nsmakerange ( the,1)].intvalue) *4+ ([Value Substringwithrange:nsmakerange (6,1)].intvalue + [value substringwithrange:nsmakerange ( -,1)].intvalue) *2+ [Value Substringwithrange:nsmakerange (7,1)].intvalue *1+ [Value Substringwithrange:nsmakerange (8,1)].intvalue *6+ [Value Substringwithrange:nsmakerange (9,1)].intvalue *3; intY = S% One; NSString*m =@"F"; NSString*jym =@"10x98765432"; M= [Jym substringwithrange:nsmakerange (Y,1)];//Judging check digit if([M Isequaltostring:[value Substringwithrange:nsmakerange ( -,1)]]) { returnYES;//check digit of detection ID }Else { returnNO; } }Else { returnNO; } default: return false; }}
iOS Verifying ID is legal