


Detailed explanation and example code of valid verification of JavaScript ID card number
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.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

Introduction to the method of obtaining HTTP status code in JavaScript: In front-end development, we often need to deal with the interaction with the back-end interface, and HTTP status code is a very important part of it. Understanding and obtaining HTTP status codes helps us better handle the data returned by the interface. This article will introduce how to use JavaScript to obtain HTTP status codes and provide specific code examples. 1. What is HTTP status code? HTTP status code means that when the browser initiates a request to the server, the service

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).
