zoukankan      html  css  js  c++  java
  • js正则表达式之密码强度验证

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    <html xmlns="http://www.w3.org/1999/xhtml">  
    <head>  
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
    <title>passwordCheck</title>  
    <script type="text/javascript" src="Js/jquery1.6.1.js"></script>  
    <script type="text/javascript">  
        $(function() {  
            $('#pwd').keyup(function() {  
                var val = $(this).val();  
                isDigit(val);  
            });  
              
            function isDigit(s) {  
                var pattern_d = /^d+$/;            //全数字  
                var pattern_s = /^[A-Za-z]+$/       //全字符  
                var pattern_w = /^w+$/;            //数字或者字符  
                var pattern_W = /^W+$/             //全非数字也非字符  
                var pattern_r = /^w+W+[wW]*w+$/    //以字母或者数字开头结尾的字符串  
                var html = '';  
                var x = 0;  
                var y = 0;  
                  
                $('#user').html(s);  
                if(pattern_W.exec(s)) {  
                    html += '非数字也非字符<br />';  
                    x = 0;  
                    y = 0;  
                }  
                if(pattern_w.exec(s)) {  
                    html += '数字或者字符<br />';  
                    y = 1;  
                }  
                if(pattern_d.exec(s)) {  
                    html += '全数字<br />';  
                    x = 1;  
                    y = 0;  
                }  
                if(pattern_s.exec(s)) {  
                    html += '全字符<br />';  
                    x = 2;  
                    y = 0;  
                }  
                if(pattern_r.exec(s)) {  
                    html += '以字母或者数字开头结尾的字符串<br />';  
                    x = 3;  
                    y = 2;  
                }  
                if( y === 0 && x === 0) {  
                    html += '密码格式错误<br />';  
                }  
                if( x > 0 && y === 0) {  
                    html += '安全级别《低》<br />';  
                }  
                if( x === 0 && y === 1) {  
                    html += '安全级别《中》<br />';  
                }  
                if( y === 2) {  
                    html += '安全级别《高》<br />';  
                }  
                html += x + '<br />' + y;  
                $('#password').html(html);  
            };  
        });  
    </script>  
    </head>  
      
    <body>  
    <form action="#" method="#">  
        用户名:<input type="text" name="" /><span id="user"></span><br />  
        密码:<input type="password" name="" id="pwd" /><span id="password"></span><br />  
    </form>  
    </body>  
    </html>  
    

      

  • 相关阅读:
    configure错误列表供参考
    php和AJAX用户注册演示程序
    php中文汉字截取函数
    阻止a标签点击跳转刷新
    js日期插件
    apache 开启Gzip网页压缩
    查询文章的上下篇Sql语句
    thinkphp简洁、美观、靠谱的分页类
    thinkphp自定义模板标签(二)
    thinkphp自定义模板标签(一)
  • 原文地址:https://www.cnblogs.com/mtl-key/p/6500728.html
Copyright © 2011-2022 走看看