JS realizes the validity verification of Chinese citizen ID number

  • 2021-07-22 08:31:50
  • OfStack

Can be directly copied and pasted to run with the function of generating ID number


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="http://demo.js.jdk5.com/jquery-1.12.3.min.js"></script>
<script type="text/javascript" src="http://demo.js.jdk5.com/IDValidator/IDValidator.js" charset="utf-8" ></script>
<script type="text/javascript" src="http://demo.js.jdk5.com/IDValidator/GB2260.js" charset="utf-8" ></script>
<title>Insert title here</title>
<style type="text/css">
div{margin: 20px;}
</style>
<script type="text/javascript">
// New Common Instance 
var Validator = new IDValidator();
// Or use an instance with an address code , Need to be introduced GB2260
//var Validator = IDValidator(GB2260);
$(function (){
 $("#isValid-btn").click(function (){
 // Verify whether the number is legal and return legally true , illegal return false
 var code = $("#isValid").val();
 var i = Validator.isValid(code);
 $("#isValid-show").html(i == false ? " Illegal number " : " Legal number ");
 });
 $("#getInfo-btn").click(function (){
 // If the number is legal, the analysis information (region, date of birth, gender, parity digit) will be returned, and if the number is illegal, it will be returned false
 var code = $("#getInfo").val();
 var i = Validator.getInfo(code);
 $("#getInfo-show").html(i == false ? " Illegal number " : JSON.stringify(i));
 });
 $("#makeID18-btn").click(function (){
 // Imitation 1 A 18 Bit ID number 
 $("#makeID18-show").html(Validator.makeID());
 });
 $("#makeID15-btn").click(function (){
 // Imitation 1 A 15 Bit ID number 
 $("#makeID15-show").html(Validator.makeID(true));
 });
});
</script>
</head>
<body>
<div>
 <input id="isValid" />
 <button id="isValid-btn"> Judge whether it is legal or not </button>
 <div id="isValid-show"></div>
</div>
<div>
 <input id="getInfo" />
 <button id="getInfo-btn"> ID Details </button>
 <div id="getInfo-show"></div>
</div>
<div>
 <button id="makeID18-btn"> Imitation 1 A 18 Bit ID number </button>
 <div id="makeID18-show"></div>
</div>
<div>
 <button id="makeID15-btn"> Imitation 1 A 15 Bit ID number </button>
 <div id="makeID15-show"></div>
</div>
</body>
</html>

Related articles: