【js正则表达式验证数字】js正则表达式验证密码强度【推荐】

更新时间:2021-07-05    来源:正则表达式    手机版     字体:

【www.bbyears.com--正则表达式】

效果图:

代码如下:

 

 代码如下

 

 验证密码强度

 

 *{margin: 0;padding: 0;}

 body{background:#ccc;}

 #demo{width:400px;padding:50px;background:#efefef;border: 1px solid #999;line-height:40px;margin:100px auto 0;}

 #strength_length{height:6px;width:100px;padding:2px;border: 1px solid #ccc;}

 .lv1{background:red;}

 .lv2{background:blue;width:200px;}

 .lv3{background:green;width:300px;}

 

 

 密码:

 

 密码强度:

 

 

<scripttype="text/javascript">

 (function(window){

 function $(id){

 return document.getElementById(id);

 };

 var arr = ["","低","中","高"];

 // 获取对象

 var ipt = $("ipt"),strength = $("strength"),strLength = $("strength_length");

 // 密码输入事件

 ipt.onkeyup = function(){

 var s = 0;

 var txt = this.value;

 if( /[a-zA-Z]/.test(txt) ){

 s++;

 };

 if( /[0-9]/.test(txt) ){

 s++;

 };

 if( /[^0-9a-zA-Z]/.test(txt) ){

 s++;

 };

 if( txt.length <6){

 s=0;

 };

 strength.innerHTML=arr[s];

 strLength.className="lv"+ s;

 }

 })(window)

</script>

 

本文来源:http://www.bbyears.com/aspjiaocheng/127847.html

热门标签

更多>>

本类排行