Recently, it is necessary to verify the legality of the ID card. Real-name verification is no longer expected. However, the original verification rules are too simple. They just simply verify the length of the ID card. Now the business needs to strengthen the ID card verification rules. I found many on the Internet. There is little information, but none of them match my wishes, so I have no choice but to write one directly. I still use my own code to verify the ID number
JavaScript to verify the ID number
<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=GB18030"> <title>身份证验证</title> <script type="text/javascript"> var arr2=[7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2]; var arr3=[1,0,'X',9,8,7,6,5,4,3,2]; function checkid(){ var t=document.getElementById("gettext").value; if(t.length==18){ var arr=t.split(''); var s; var reg = /^\d+$/; var pd=0; for(i=0;i<17;i++){ if(reg.test(arr[i])){ s=true; pd=arr[i]*arr2[i]+pd; }else{ s=false; break; } } if(s=true){ var r=pd%11; if(arr[17]==arr3[r]){ document.getElementById("show").innerHTML="身份证号合法 尾号为:"+arr3[r]; }else{ document.getElementById("show").innerHTML="非合法身份证号"; } } }else{ document.getElementById("show").innerHTML="非合法身份证号"; } } </script> </head> <body > <input id="gettext" type="text" size="30" onkeyup="checkid()"> <p id="show"></p><br> </body> </html>
An identity verification written based on the calculation formula of the online ID card js for ID number
Step 1: Multiply the first digit of the ID number by 7; multiply the second digit of the ID number by 9; multiply the third digit of the ID number by 10 Multiply; multiply the 4th digit of the ID number by 5; multiply the 5th digit of the ID number by 8; multiply the 6th digit of the ID number by 4; multiply the 6th digit of the ID number by 4 Multiply the 7-digit number by 2; multiply the 8th digit of the ID number by 1; multiply the 9th digit of the ID number by 6; multiply the 10th digit of the ID number by 3; Multiply the 11th digit of the ID number by 7; multiply the 12th digit of the ID number by 9; multiply the 13th digit of the ID number by 10; multiply the 14th digit of the ID number. Multiply the number by 5; multiply the 15th digit of the ID number by 8; multiply the 16th digit of the ID number by 4; multiply the 17th digit of the ID number by 2.
Step 2: Sum the results of multiplying 1 to 17 digits of the ID number in the first step and add them all up.
Step 3: Divide the result calculated in the second step by 11, so that the remainder is 0, the remainder is 1, the remainder is 2, the remainder is 3, the remainder is 4, the remainder is 5, the remainder is 6, The remainder is 7, the remainder is 8, the remainder is 9, the remainder is 10, a total of 11 possibilities.
Step 4: If the remainder is 0, then the corresponding number of the last ID card is 1; if the remainder is 1, then the corresponding number of the last ID card is 0; if the remainder is 2, then the corresponding number The number of the last ID card is X; if the remainder is 3, the corresponding number of the last ID card is 9; if the remainder is 4, the corresponding number of the last ID card is 8; if the remainder is 5 , then the corresponding number of the last ID card is 7; if the remainder is 6, then the corresponding number of the last ID card is 6; if the remainder is 7, then the number of the corresponding last ID card is 5; If the remainder is 8, then the corresponding number of the last ID card is 4; if the remainder is 9, then the number of the corresponding last ID card is 3; if the remainder is 10, then the number of the corresponding last ID card is 3 The number is 2.