function Checkidcard (num) { num = Num.touppercase (); The ID number is 15 digits or 18 digits, 15 digits are all digits, 18 digits are the first 17 digits, and the last is a check digit, possibly a number or a character X. if (!) ( /(^\d{15}$) | (^\d{17} ([0-9]| X) $)/.test (num)) { Alert (' Enter the ID number is not the right length, or the number does not meet the requirements! \n15 digit number should be full, 18 digits can be the lowest number or X. '); return false; } The check digit is generated according to ISO 7064:1983.mod 11-2, and X can be considered to be the number 10. The following analysis of birth date and check digit respectively var len, re; len = num.length; if (len = = 15) { Re = new RegExp (/^ (\d{6}) (\d{2}) (\d{2}) (\d{2}) \d{3); var arrsplit = Num.match (re);
Check if the birthday date is correct var Dtmbirth = new Date (' ' + arrsplit[2] + '/' + arrsplit[3] + '/' + arrsplit[4] "; var bgoodday; Bgoodday = (dtmbirth.getyear () = = number (arrsplit[2]) && ((Dtmbirth.getmonth () + 1) = = number (arrsplit[3)) ;& (dtmbirth.getdate () = = number (arrsplit[4])); if (!bgoodday) { Alert (' entered the ID number in the wrong birth date! '); return false; } Else { Turn 15 ID cards into 18-bit The check digit is generated according to ISO 7064:1983.mod 11-2, and X can be considered to be the number 10. var arrint = new Array (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); var arrch = new Array (' 1 ', ' 0 ', ' X ', ' 9 ', ' 8 ', ' 7 ', ' 6 ', ' 5 ', ' 4 ', ' 3 ', ' 2 '); var ntemp = 0, I; num = num.substr (0, 6) + ' n ' + num.substr (6, num.length-6); for (i = 0; i < i + +) { Ntemp + + NUM.SUBSTR (i, 1) * arrint[i]; } num + + arrch[ntemp% 11]; return true; } } if (len = = 18) { Re = new RegExp (/^ (\d{6}) (\d{4}) (\d{2}) (\d{2}) (\d{3}) ([0-9]| X) $/); var arrsplit = Num.match (re);
Check if the birthday date is correct var Dtmbirth = new Date (arrsplit[2] + "/" + arrsplit[3] + "/" + arrsplit[4]); var bgoodday; Bgoodday = (dtmbirth.getfullyear () = = number (arrsplit[2]) && ((Dtmbirth.getmonth () + 1) = = number (arrsplit[3)) && (dtmbirth.getdate () = = number (arrsplit[4]); if (!bgoodday) { Alert (' entered the ID number in the wrong birth date! '); return false; } Else { Verify that the check code for the 18-bit ID card is correct. The check digit is generated according to ISO 7064:1983.mod 11-2, and X can be considered to be the number 10. var valnum; var arrint = new Array (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); var arrch = new Array (' 1 ', ' 0 ', ' X ', ' 9 ', ' 8 ', ' 7 ', ' 6 ', ' 5 ', ' 4 ', ' 3 ', ' 2 '); var ntemp = 0, I; for (i = 0; i < i + +) { Ntemp + + NUM.SUBSTR (i, 1) * arrint[i]; } Valnum = arrch[ntemp% 11]; if (Valnum!= num.substr (17, 1)) { Alert (' 18-bit ID card is not the correct check code! should be: ' + valnum '; return false; } return true; } } return false; } |