Maison > interface Web > js tutoriel > le corps du texte

javascript验证身份证完全方法具体实现_javascript技巧

WBOY
Libérer: 2016-05-16 17:14:22
original
1041 Les gens l'ont consulté

复制代码 代码如下:

var certCardValid = function(id){
        var arrVerifyCode = [1,0,"x",9,8,7,6,5,4,3,2];
        var wi = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2];
        var Checker = [1,9,8,7,6,5,4,3,2,1,1];
        var msg = "";
        if(id.length != 15 && id.length != 18) {
            Ext.MessageBox.alert("信息提示","身份证号共有15位或18位。");
            return false;
        }

        var ai = id.length == 18 ?  id.substring(0,17) : id.slice(0,6) + "19" + id.slice(6,16);

 
        if (!/^/d+$/.test(ai)) {
            Ext.MessageBox.alert("信息提示","身份证除最后一位外,必须为数字。");
            return false;
        } 

 
        var yyyy = ai.slice(6,10);
        var mm = ai.slice(10,12)-1; 
        var dd = ai.slice(12,14);
        var d = new Date(yyyy,mm,dd);
        var now = new Date();
        var year = d.getFullYear();
        var mon = d.getMonth(); 
        var day = d.getDate();

 
        if (year != yyyy || mon != mm || day != dd) {
            Ext.MessageBox.alert("信息提示","身份证无效。");
            return false;
        }

 
        for(var i = 0,ret = 0; i             ret += ai.charAt(i) * wi[i];
        }

        ai += arrVerifyCode[ret %= 11];
        ai = ai.toUpperCase();

 
        if(id.length == 18 && id != ai){
            Ext.MessageBox.alert("信息提示","身份证无效。");
            return false;
        }
        return true;
    };
Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!