This article mainly introduces JS to implement the validity verification of Chinese citizen ID numbers. It is very good and has reference value. Friends in need can refer to it
You can directly copy and paste and run to generate the ID number. Function
<!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"> p{margin: 20px;} </style> <script type="text/javascript"> //新建普通实例 var Validator = new IDValidator(); //或使用带地址码实例,需要引入GB2260 //var Validator = IDValidator(GB2260); $(function (){ $("#isValid-btn").click(function (){ //验证号码是否合法,合法返回true,不合法返回false var code = $("#isValid").val(); var i = Validator.isValid(code); $("#isValid-show").html(i == false ? "号码不合法" : "号码合法"); }); $("#getInfo-btn").click(function (){ //号码合法时返回分析信息(地区、出生日期、性别、校验位),不合法返回false var code = $("#getInfo").val(); var i = Validator.getInfo(code); $("#getInfo-show").html(i == false ? "号码不合法" : JSON.stringify(i)); }); $("#makeID18-btn").click(function (){ //仿造一个18位身份证号 $("#makeID18-show").html(Validator.makeID()); }); $("#makeID15-btn").click(function (){ //仿造一个15位身份证号 $("#makeID15-show").html(Validator.makeID(true)); }); }); </script> </head> <body> <p> <input id="isValid" /> <button id="isValid-btn">判断是否合法</button> <p id="isValid-show"></p> </p> <p> <input id="getInfo" /> <button id="getInfo-btn">身份证详细信息</button> <p id="getInfo-show"></p> </p> <p> <button id="makeID18-btn">仿造一个18位身份证号</button> <p id="makeID18-show"></p> </p> <p> <button id="makeID15-btn">仿造一个15位身份证号</button> <p id="makeID15-show"></p> </p> </body> </html>
The above is the JS introduced by the editor to verify the validity of the Chinese citizen ID number. I hope it will be helpful to everyone. , if you have any questions, please leave me a message, and the editor will reply to you in time. I would also like to thank you all for your support of the PHP Chinese website!
For more articles related to JS implementation of Chinese citizen ID number validity verification, please pay attention to the PHP Chinese website!