<!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. Microsoft Office 2010 requires 的 MSXML 版本 6.10.1129.0 be 已安装在您计算机的安装"的基于 Windows 7 的计算机上安装 Office 2010 时出现错误消息

    https://support.microsoft.com/zh-cn/kb/2290714

  2. kinect 录制彩色和深度视频

    安装 KinectSDK-v1.8-Setup.exe OpenNI-Windows-x86-2.1.0.msi Qt工程 拷贝 Redist 下内容到 编译的exe所在目录 #include < ...

  3. python2.7系列安装失败的办法

    在windows系统上安装python时出现"there is a problem with your Windows installer package. A program run as ...

  4. Python在centos下的安装

    1.wget http://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz默认下载到主目录下 2.tar xzf Python-2.6.6.tgz 3 ...

  5. win7 共享的问题,"您可能没有权限使用网络资源"的解决办法

    重点来了,如果以上方法都不行的话,下面这个绝对有效,本人屡试不爽.1 打开受访者的guest权限2 开始--运行--gpedit.msc3 windows设置---安全设置--本地策略--用户权利指派 ...

  6. [转] js prototype详解

    JavaScript能够实现的面向对象的特征有:·公有属性(public field)·公有方法(public Method)·私有属性(private field)·私有方法(private fie ...

  7. tableView 显示区域偏移

    在SB拖了一个tableView , 在显示的时候显示区域和tableView的区域不一致, (UITableViewWrapperView 和 UITableView frame不一致) 在SB上看 ...

  8. SQL Server 字符串函数

    字符串函数 在开发T-SQL时,经常会需要对字符串进行各种各样的操作,下面介绍常用的字符串函数. 1.获取字符的ASCII码 ASCII ASCII码是对字符的标准编码.要获取字符的ASCII码就可以 ...

  9. InternetOpenA

    [ilink32 Error] Error: Unresolved external 'InternetOpenA' referenced from  ..\WIN32\DEBUG\NATIVEXML ...

  10. <<海闻电子发票接口 ESB 封装 代码指示 文档>>

    <<海闻电子发票接口 ESB 封装 代码指示 文档>> isValid 是否有效标志 代码 中文 说明 true 成功 false 失败   code 海闻错误说明 代码 中文 ...