<!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>密码强度检测</title>
<style type="text/css">
body {
font: 12px/1.5 Arial;
}
input {
float: left;
font-size: 12px;
width: 150px;
font-family: arial;
border: 1px solid #ccc;
padding: 3px;
}
input.correct {
border: 1px solid green;
}
input.error {
border: 1px solid red;
}
#tips {
float: left;
margin: 2px 0 0 20px;
}
#tips span {
float: left;
width: 50px;
height: 20px;
color: #fff;
overflow: hidden;
background: #ccc;
margin-right: 2px;
line-height: 20px;
text-align: center;
}
#tips.s1 .active {
background: #f30;
}
#tips.s2 .active {
background: #fc0;
}
#tips.s3 .active {
background: #cc0;
}
#tips.s4 .active {
background: #090;
}
</style>
<script type="text/javascript">
window.onload = function() {
var oTips = document.getElementById("tips");
var oInput = document.getElementsByTagName("input")[0];
var aSpan = oTips.getElementsByTagName("span");
var aStr = ["弱", "中", "强", "非常好"];
var i = 0; oInput.onkeyup = oInput.onfocus = oInput.onblur = function() {
var index = checkStrong(this.value);
this.className = index ? "correct" : "error";
oTips.className = "s" + index;
for ( i = 0; i < aSpan.length; i++)
aSpan[i].className = aSpan[i].innerHTML = "";
if(index==4){
index && (aSpan[index - 1].className = "active", aSpan[index - 1].innerHTML = aStr[index - 1]);
index && (aSpan[index - 2].className = "active", aSpan[index - 2].innerHTML = aStr[index - 2]);
index && (aSpan[index - 3].className = "active", aSpan[index - 3].innerHTML = aStr[index - 3]);
index && (aSpan[index - 4].className = "active", aSpan[index - 4].innerHTML = aStr[index - 4]);
}else if(index==3){
index && (aSpan[index - 1].className = "active", aSpan[index - 1].innerHTML = aStr[index - 1]);
index && (aSpan[index - 2].className = "active", aSpan[index - 2].innerHTML = aStr[index - 2]);
index && (aSpan[index - 3].className = "active", aSpan[index - 3].innerHTML = aStr[index - 3]);
}else if(index==2){
index && (aSpan[index - 1].className = "active", aSpan[index - 1].innerHTML = aStr[index - 1]);
index && (aSpan[index - 2].className = "active", aSpan[index - 2].innerHTML = aStr[index - 2]);
}else if(index==1){
index && (aSpan[index - 1].className = "active", aSpan[index - 1].innerHTML = aStr[index - 1]);
} };
};
/** 强度规则
+ ------------------------------------------------------- +
1) 任何少于6个字符的组合,弱;任何字符数的同类字符组合,弱;
2) 任何字符数的两类字符组合,中;
3) 12位字符数以下的三类或四类字符组合,强;
4) 12位字符数以上的三类或四类字符组合,非常好。
+ ------------------------------------------------------- +
**/
//检测密码强度
function checkStrong(sValue) {
var modes = 0;
if (sValue.length < 6)
return modes;
if (/\d/.test(sValue))
modes++;
//数字
if (/[a-z]/.test(sValue))
modes++;
//小写
if (/[A-Z]/.test(sValue))
modes++;
//大写
if (/\W/.test(sValue))
modes++;
//特殊字符
switch (modes) {
case 1:
return 1;
break;
case 2:
return 2;
case 3:
case 4:
return sValue.length < 12 ? 3 : 4;
break;
}
}
</script>
</head>
<body>
<input type="password" value="" maxlength="16" />
<div id="tips">
<span></span><span></span><span></span><span></span>
</div>
</body>
</html>

js密码强度的更多相关文章

  1. JS密码强度检测

    //校验密码强度---沒有匹配到以下級別就提示 function checkPassWord(value){ // 0: 表示第一个级别 1:表示第二个级别 2:表示第三个级别 // 3: 表示第四个 ...

  2. js密码强度校验

    function AuthPasswd(string) { if(!string){ jQuery("#low").removeClass("org"); }) ...

  3. js实现密码强度

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  4. JS正则检测密码强度

    今天遇到个需求,使用JS检测密码强度:密码长度最短为8,必须同时包含字母.数字.特殊符号. 代码如下: /*         * 检测密码复杂度         */         function ...

  5. js判断密码强度

    html代码: <form name="form1" action=""> 密码:<input type="password&quo ...

  6. js动态判断密码强度&&实用的 jQuery 代码片段

    // 网上拷贝的代码,效果不太好需要自己调整<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &q ...

  7. 密码强度的js插件(完成)

    效果如下图: 低:

  8. js 检验密码强度

    html 代码如下: <!DOCTYPE HTML> <html lang="en"> <head> <meta charset=&quo ...

  9. js实现密码强度验证

    <html> <head> <meta http-equiv="content-type" content="text/html" ...

随机推荐

  1. [转]Linux文件和目录操作命令

    转自:http://www.linuxdiyf.com/bbs/thread-416176-1-1.html 一.文件操作命令1.1 查看文件 Linux下查看文件的命令有很多,下面列出的几个是几乎所 ...

  2. HTML5_布局and音视频

    HTML5_布局and音视频 I.HTML5标签的改变1.文档声明HTML语法是不区分大小写的HTML5的DTD声明为:<!doctype html>确保浏览器能在HTML5的标准模式下进 ...

  3. 【LeetCode】217 & 219 - Contains Duplicate & Contains Duplicate II

     217 - Contains Duplicate Given an array of integers, find if the array contains any duplicates. You ...

  4. 分区表,桶表,外部表,以及hive一些命令行小工具

    hive中的表与hdfs中的文件通过metastore关联起来的.Hive的数据模型:内部表,分区表,外部表,桶表受控表(managed table):包括内部表,分区表,桶表 内部表: 我们删除表的 ...

  5. focus与定位

    <html> <head> <script type="text/javascript" src="/jquery/jquery.js&qu ...

  6. linux 操作总结

    1.集群节点之间ssh无密码登陆 参考:http://www.cnblogs.com/jdksummer/articles/2521550.html 解决: 1)删除旧有记录:rm -r ~/.ssh ...

  7. html5 canvas 钟表

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  8. C++ __int64用法(转)

    在做ACM题时,经常都会遇到一些比较大的整数.而常用的内置整数类型常常显得太小了:其中long 和 int 范围是[-2^31,2^31),即-2147483648~2147483647.而unsig ...

  9. How to setup Wicket Examples in Eclipse

    Wicket examples is a good place to learn Apache Wicket by examples, and a must reference site for ne ...

  10. Python基础 列表

    ---***---传送门---***--- 文档解释 def append(self, p_object): """ L.append(object) -> Non ...