IOS ID Check
Last Update:2015-08-11
Source: Internet
Author: User
<span id="Label3"></p><p><p>Original: http://blog.csdn.net/afyzgh/article/details/16965107</p></p><p><p>The original text directly copied, there will be small errors, the original version of Java verification, There is need to take the original spice.</p></p><p><p>The following are the Xcode arc tests Passed.</p></p><p><p></p></p><p><p>+ (BOOL) validateidcardnumber: (nsstring *) Value {</p></p><p><p>Value = [value Stringbytrimmingcharactersinset:[nscharacterset whitespaceandnewlinecharacterset]];</p></p><p><p></p></p><p><p>int length = 0;</p></p><p><p>If (!value) {</p></p><p><p>Return NO;</p></p><p><p>}else {</p></p><p><p>Length = (int) value.length;</p></p><p><p></p></p><p><p>If (length! = && Length!=18) {</p></p><p><p>Return NO;</p></p><p><p>}</p></p><p><p>}</p></p><p><p>Province code</p></p><p><p>Nsarray *areasarray [email protected][@ "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", @ "6 4 ", @" 65 ", @" 71 ", @" 81 ", @" 82 ", @" 91 "];</p></p><p><p></p></p><p><p>NSString *valuestart2 = [value substringtoindex:2];</p></p><p><p>BOOL Areaflag = NO;</p></p><p><p>For (nsstring *areacode in Areasarray) {</p></p><p><p>If ([areacode isequaltostring:valuestart2]) {</p></p><p><p>Areaflag =yes;</p></p><p><p>Break</p></p><p><p>}</p></p><p><p>}</p></p><p><p></p></p><p><p>If (!areaflag) {</p></p><p><p>Return false;</p></p><p><p>}</p></p><p><p></p></p><p><p></p></p><p><p>Nsregularexpression *regularexpression;</p></p><p><p>Nsuinteger numberofmatch;</p></p><p><p></p></p><p><p>int year = 0;</p></p><p><p>Switch (length) {</p></p><p><p>Case 15:</p></p><p><p>Year = [value Substringwithrange:nsmakerange (6,2)].intvalue +1900;</p></p><p><p></p></p><p><p>If (year% 4 ==0 | | (year% ==0 && year% 4 ==0)) {</p></p><p><p></p></p><p><p>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}$]</p></p><p><p>Options:nsregularexpressioncaseinsensitive</p></p><p><p>Error:nil];//testing the legality of birth date</p></p><p><p>}else {</p></p><p><p>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}$]</p></p><p><p>Options:nsregularexpressioncaseinsensitive</p></p><p><p>Error:nil];//testing the legality of birth date</p></p><p><p>}</p></p><p><p>Numberofmatch = [regularexpression Numberofmatchesinstring:value</p></p><p><p>Options:nsmatchingreportprogress</p></p><p><p>Range:nsmakerange (0, value.length)];</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p>If (numberofmatch > 0) {</p></p><p><p>Return YES;</p></p><p><p>}else {</p></p><p><p>Return NO;</p></p><p><p>}</p></p><p><p>Case 18:</p></p><p><p></p></p><p><p>Year = [value Substringwithrange:nsmakerange (6,4)].intvalue;</p></p><p><p>If (year% 4 ==0 | | (year% ==0 && year% 4 ==0)) {</p></p><p><p></p></p><p><p>RegularExpression = [[nsregularexpression alloc] initwithpattern:@ "^[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]$]</p></p><p><p>Options:nsregularexpressioncaseinsensitive</p></p><p><p>Error:nil];//testing the legality of birth date</p></p><p><p>}else {</p></p><p><p>RegularExpression = [[nsregularexpression alloc] initwithpattern:@ "^[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[0-9]|2[0-8])) [0-9]{3}[0-9xx]$]</p></p><p><p>Options:nsregularexpressioncaseinsensitive</p></p><p><p>Error:nil];//testing the legality of birth date</p></p><p><p>}</p></p><p><p>Numberofmatch = [regularexpression Numberofmatchesinstring:value</p></p><p><p>Options:nsmatchingreportprogress</p></p><p><p>Range:nsmakerange (0, value.length)];</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p>If (numberofmatch > 0) {</p></p><p> int S = ([value Substringwithrange:nsmakerange (0,1)].intvalue + [v] Alue substringwithrange:nsmakerange (10,1)].intvalue) *7 + ([value Substringwithrange:nsmakerange]].intValue + [ Value Substringwithrange:nsmakerange (11,1)].intvalue) *9 + ([value substringwithrange:nsmakerange (2,1)].intValue + [ Value Substringwithrange:nsmakerange (12,1)].intvalue) *10 + ([value substringwithrange:nsmakerange (3,1)].intValue + [ Value Substringwithrange:nsmakerange (13,1)].intvalue) + ([value substringwithrange:nsmakerange (4,1)].intValue + [ Value Substringwithrange:nsmakerange (14,1)].intvalue) *8 + ([value substringwithrange:nsmakerange (5,1)].intValue + [ Value Substringwithrange:nsmakerange (15,1)].intvalue) + ([value substringwithrange:nsmakerange (6,1)].intValue + [ Value Substringwithrange:nsmakerange (16,1)].intvalue) * + [value substringwithrange:nsmakerange (7,1)].intValue * + [ Value Substringwithrange:nsmakerange (8,1)].intvalue *6 + [valueSubstringwithrange:nsmakerange (9,1)].intvalue; </p><p><p>int Y = S% 11;</p></p><p><p>NSString *m = @ "F";</p></p><p><p>NSString *jym = @ "10x98765432";</p></p><p><p>M = [jym Substringwithrange:nsmakerange (y,1)]; Judging check digit</p></p><p><p>If ([M isequaltostring:[value substringwithrange:nsmakerange (17,1)]]) {</p></p><p><p>Return yes;//check digit for detection ID</p></p><p><p>}else {</p></p><p><p>Return NO;</p></p><p><p>}</p></p><p><p></p></p><p><p>}else {</p></p><p><p>Return NO;</p></p><p><p>}</p></p><p><p>Default</p></p><p><p>Return false;</p></p><p><p>}</p></p><p><p>}</p></p><p><p></p></p><p><p>IOS ID Check</p></p></span>