网站地图    收藏   

主页 > 前端 > javascript >

javascript验证密码强度代码

来源:未知    时间:2015-07-31 12:52 作者:xxadmin 阅读:

[导读] 本文讲解javascript验证密码强度代码 scriptvarrules=[{reg:/\d+/,weight:2},{reg:/[a-z]+/,weight:4},{reg:/[A-Z]+/,weight:8},{reg:/[~!@#\$%^*\(\)\{\};,.\?\/]/,weight:16}];varstrongLevel={0-10:弱,10-20:中,20-30:强};vartestPasswords...

本文讲解javascript验证密码强度代码

<script>
var rules=[{
    reg:/\d+/,
    weight:2
},{
    reg:/[a-z]+/,
    weight:4
},{
    reg:/[A-Z]+/,
    weight:8
},{
    reg:/[~!@#\$%^&*\(\)\{\};,.\?\/'"]/,
    weight:16
}];

var strongLevel={
    '0-10':'弱',
    '10-20':'中',
    '20-30':'强'
};
var testPasswords=['123456','abc123','abA123','B1','#@123','@#12abcABC'];
for(var i=0;i<testPasswords.length;i++){
    var weight=0;
    for(var j=rules.length-1;j>=0;j--){
        if(rules[j].reg.test(testPasswords[i])){
            weight|=rules[j].weight;
        }
    }
    var key='20-30';
    if(weight<=10)key='0-10';
    else if(weight<=20)key='10-20';
    console.log(testPasswords[i],strongLevel[key]);
}
</script>


自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论