JavaScript的方法:

     <script type="text/javascript">
window.onload = function () {
document.getElementById('txt').onkeydown = function () { //获取td
var tds = document.getElementById('tb').getElementsByTagName('td');
for (var i = 0; i < tds.length; i++) {
tds[i].style.backgroundColor = '#E6E6E6';
} var pwd = this.value; //获取密码
if (pwd.length > 0) {
var result = getPassWord(pwd);
if (result <= 1) {
//弱
tds[0].style.backgroundColor = 'red';
} else if (result == 2) {
//中
tds[0].style.backgroundColor = 'orange';
tds[1].style.backgroundColor = 'orange';
} else if (result == 3) {
//强
tds[0].style.backgroundColor = 'green';
tds[1].style.backgroundColor = 'green';
tds[2].style.backgroundColor = 'green';
} }
}
}
//利用正则表达式匹配相关字符串,返回密码的强度值
function getPassWord(pwdMsg) {
var lvl = 0;
/*
var reg = /\d/;
if (reg.test(pwdMsg)) {
lvl++;
};
*/
//密码中有数字加1
if (pwdMsg.match(/\d/)) {
lvl++;
}
//密码中有字符加1
if (pwdMsg.match(/[a-zA-Z]/)) {
lvl++;
}
//密码中有其他字符加1
if (pwdMsg.match(/^[0-9a-zA-Z]/)) {
lvl++;
}
//密码小于6位减一
if (pwdMsg.length <= 6) {
lvl--;
}
return lvl;
}
</script>

页面内容:

 <input type="text" id="txt" name="name" value="" />
<table border="1" cellpadding="0" cellspacing="0" id="tb">
<tr>
<td>

</td>
<td>

</td>
<td>

</td>
</tr>
</table>

简单的样式:

 <style type="text/css">
td
{
width: 100px;
height: 25px;
background-color: #E6E6E6;
text-align: center;
}
</style>

JavaScript验证密码强度的更多相关文章

  1. JS简单验证密码强度

    <input type="password" id="password" value=""/><button id=&qu ...

  2. javascript 检测密码强度

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. JavaScript判断密码强度

    以下是代码: <html> <head> <title>JS判断密码强度</title> <script language=javascript& ...

  4. jquery用正则表达式验证密码强度

    /**         * 不加paste鼠标粘贴不起作用         * 不加input第一次粘贴的时候不变         * 加上input和focus可以兼容表情         * ke ...

  5. javascript 检测密码强度 美化版

    模仿美团的美化 <!DOCTYPE> <head runat="server"> <title></title> <link ...

  6. MySQL密码强度验证修改

    MySQL5.6.6版本之后增加了密码强度验证插件validate_password,相关参数设置的较为严格. 影响的语句和函数有:create user,grant,set password,pas ...

  7. 密码强度应用(js)

    <!-- 密码强度div --> <div id="tips" class="help-block"> <b class=&quo ...

  8. JS简单验证password强度

    <input type="password" id="password" value=""/><button id=&qu ...

  9. mysql 5.6密码强度插件使用

    在mysql 5.6对密码的强度进行了加强,推出了validate_password 插件.支持密码的强度要求. 此插件要求版本:5.6.6 以上版本安装方式: 1.安装插件:(默认安装了插件后,强度 ...

随机推荐

  1. 逆序数 HDOJ 4911 Inversion

    题目传送门 题意:可以交换两个相邻的数字顺序k次,问最后逆序对最少有多少 分析:根据逆序数的定理如果逆序数大于0,那么必定存在1<=i<n使得i和i+1交换后逆序数减1假设原逆序数为cnt ...

  2. JS防止页面被其他网站iframe使用方法

    if(window.top !== window.self){ window.top.location = window.location;} 这句话的意识是说:如果当前窗体不是顶级窗体,就把自己变成 ...

  3. php Try Catch多层级异常测试

    <?php class a { public function a1 () { try { throw new Exception('123'); } catch (Exception $e) ...

  4. ES6初探——编译环境搭建

    不好意思我又要来写操作文档了,看起来更像wiki的博客(如果你想深入学习,请阅读文末列的参考资料).本文将示例如何把ES6编译成ES5. 首先,你要自行查阅什么是ES6,和ES5.javascript ...

  5. Windows API函数大全四

    10. API之硬件与系统函数 ActivateKeyboardLayout 激活一个新的键盘布局.键盘布局定义了按键在一种物理性键盘上的位置与含义 Beep 用于生成简单的声音 CharToOem ...

  6. SpringBoot 2.x (7):拦截器

    类似以前SpringMVC的拦截器,但也有一些区别 SpringBoot的拦截器有两种方式: 第一种方式:过时的方式,适用于SpringBoot1.x的方式 package org.dreamtech ...

  7. C++模板类头文件和实现文件分离

    http://www.cnblogs.com/lvdongjie/p/4288373.html 如何实现C++模板类头文件和实现文件分离,这个问题和编译器有关. 引用<<C++primer ...

  8. linux php扩展安装gettext

    php解压后的文件路径为/usr/local/src/php-5.2.6 php 的安装路径为/usr/local/php [root@localhost# cd  /usr/local/src/ph ...

  9. guanbi selinux

    编辑/etc/sysconfig/selinux,把第一条选项改为 disabled

  10. IOS文件下载

    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,  NSUserDomainMask, ...