JavaScript ID card check (original)

zhaozj2021-02-16  48

// ID card number check, and split the birthday and gender VAR YYYYYYY; var mm; var sex; var.

function getYear () {return yyyy;} function getMonth () {return mm;} function getDate () {return dd;} function getBirthday () {return birthday;} function getSex () {return sex;} function getAge () { VAR mm = getMonth (); if (mm <10) mm = mm.substring (1, 2); return math.floor ((PARSEINT ()) * 12 PARSEINT (_GETMONTH ()) - PARSEINT (GetYear ))) * 12-parseint (mm)) / 12);} // Judgment whether older, male 50, female 40function isbigage () {if (Parseint (GetSeX)> === 2) Return "1"; if (Parseint)> = 50 && parseint (getsex ()) == 1) Return "1"; return "0";} // Check ID number Function CheckValue IDCARD) {var ID = idcard; var id_length = id.length;

IF (id_length == 0) {alert ("Please enter the ID number!"); return false;}

IF (id_length! = 15 && id_length! = 18) {alert ("ID number should be 15 or 18!"); Return False;

IF (id_length == 15) {yyyy = "19" id.substring (6, 8); mm = id.substring (8, 10); dd = id.substring (10, 12);

IF (mm> 12 || mm <= 0) {alert ("Enter ID number, month illegal!"); return false;}

IF (DD> 31 || DD <= 0) {Alert ("Enter your ID number, date illegal!"); Return False;

Birthday = yyyy "-" mm " DD;

IF ("13579" .indexof (id.substring (14,15))! = - 1) {sex = "1";} else {sex = "2";}} else if (id_length == 18) {IF (id.indexof ("x")> 0 && id.indexof ("x")! = 17 || id.indexof ("x")> 0 && id.indexof ("x")! = 17) {Alert ("Identification /" x / "input location is incorrect!"); Return false;} yyyy = id.substring (6, 10); if (YYYY> 2200 || yyyy <1900) {alert ("Enter your identity Diagram number, annual illegal! "); Return false;}

MM = id.substring (10, 12); if (mm> 12 || mm <= 0) {Alert ("Enter ID number, month illegal!"); Return False;

DD = id.substring (12,14); if (DD> 31 || DD <= 0) {alert ("Enter ID number, date illegal!"); return false;}

IF (id.charat (17) == "x" || ID.CHARAT (17) == "x") {if ("x"! = getverifybit (id) && "x"! = getverifybit (id)) {Alert ("ID card check error, please check the last one!"); Return false;}

} else {if (id.charat (17)! = getverifybit (ID)) {alert ("ID card check error, please check the last one!"); return false;}}

Birthday = id.substring (6,10) " id.substring (10, 12) " - id.substring (12,14); if ("13579" .indexof (id.substring (16 , 17))> -1) {sex = "1";} else {sex = "2";}}

Return true;} // 15 bits into 18 bits, calculate the last function getverifybit (id) {var result; var nnum = evult; var nnum = evult; var nnum = evult; * 9 id.Charat (2) * 10 id.Charat (3) * 5 id.Charat (4) * 8 id.Charat (5) * 4 id.Charat (6) * 2 ID. Charat (7) * 1 id.Charat (8) * 6 id.Charat (9) * 3 id.Charat (10) * 7 id.Charat (11) * 9 id.charat (12) * 10 id.Charat (13) * 5 id.Charat (14) * 8 id.Charat (15) * 4 id.Charat (16) * 2); nnum = nnum% 11; switch (nnum) { Case 0: Result = "1"; Break; Case 1: Result = "0"; Break; Case 2: Result = "x"; Break; Case 3: Result = "9"; Break; Case 4: Result = " 8 "; Break; Case 5: Result =" 7 "; Break; Case 6: Result =" 6 "; Break; Case 7: Result =" 5 "; Break; Case 8: Result =" 4 "; Break; Case; 9: Result = "3"; Break; case 10: result = "2"; break;} //document.write(Result) Return Result;} // 15 Bit 18 Bit Function Get18 (IDCARD) {if (CHECKVALUE (IDCARD)) {var ID = idcard; var ID18 = id; if (id.length == 0) {Alert ("please Enter 15-digit ID number! "); Return false;} if (id.length == 15) {if (id.substring (6,8)> 20) {id18 = id.substring (0,6) " 19 " id.substring 6, 15);} else {id18 = id.substring (0,6) "20" id.substring (6,15);} ID18 = ID18 GETVERIFYBIT (ID18);

Return ID18;} else {returnaf false;}}

转载请注明原文地址:https://www.9cbs.com/read-21410.html

New Post(0)