首页 > 其他 > 详细

身份证号校验

时间:2021-01-04 14:37:34      阅读:25      评论:0      收藏:0      [点我收藏+]
身份证号码验证规则

输入身份证号码:
提交
 
代码如下:
<!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=utf-8"/>
<title>身份证号码验证规则</title>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
<script>
    $(function(){
    $(.btn).click(function(){
        let orginnumber =$(.number).val();
        let partn = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;//先用正则判断是否为正确的格式
        if (!partn.exec(orginnumber))
        {
        alert(请检查你输入的身份证个式是否正确!);
        }else{
            let number = [...orginnumber]; //es6语法,利用...将变量的值转成数组。
            let ration= new Array("7","9","10","5","8","4","2","1","6","3","7","9","10","5","8","4","2");//系数
            let ration22= new Array("1","0","X","9","8","7","6","5","4","3","2");
            let sum=0;
            console.log(ration);
                for(let i=0;i<number.length-1;i++){
                    sum=number[i]*ration[i]+sum;
                        console.log(i);
                }
                let mod = sum%11;
                if(ration22[mod]==number[17]){
                    alert(正确);
                }else{
                    alert(不正确);
                }
            }
        })
    })
</script>
</head>
    <body>
        <div>
            <lable for="input">输入身份证号码:</lable><input type="text" class="number"/><button class="btn">提交</button>
        </div>
    </body>
</html>

转自https://www.cnblogs.com/silen0119/p/11430826.html

身份证号校验

原文:https://www.cnblogs.com/gopark/p/14228895.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!