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. [WOJ1583]向右看齐

    题目链接: WOJ1583 题目分析: 大水题--我就来水个题解 倒序扫,单调栈维护单减序列,每个对象的答案是栈里它下面那个元素 代码: #include<bits/stdc++.h> # ...

  2. [转]Java中Date转换大全,返回yyyy-MM-dd的Date类型

    /** * 获取现在时间,这个好用 * * @return返回长时间格式 yyyy-MM-dd HH:mm:ss */ public static Date getSqlDate() { Date s ...

  3. freertos之特点

    主要特点:协程(co-routine):任务间的中断通信机制              支持可抢占式/协作式任务调度 .FreeRTOS-MPU              内核对象可以动态或静态分配 ...

  4. 分享几个自己喜欢的前端UI框架

    http://www.layui.com/ http://element-cn.eleme.io/#/zh-CN/component/installation

  5. match,location,history

    哇,平常写路由时基本就是简单的按照组件给的示例写,从来没有考虑为什么,又遇见了路由相关的问题,先记录一下问题,好好捋一下,哎,好香要个大佬来带带我呀,每次遇到问题要解决好久 问题: 判断是否登录之后跳 ...

  6. COGS 2274. [HEOI 2016] tree

    ★☆   输入文件:heoi2016_tree.in   输出文件:heoi2016_tree.out   简单对比时间限制:1 s   内存限制:128 MB 这道题数据弱到炸了 . 第一次做用树刨 ...

  7. IOS中经典的缓存对比

    http://bpoplauschi.wordpress.com/2014/03/21/ios-image-caching-sdwebimage-vs-fastimage/

  8. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'needDao' defined in URL

    这个是我修改过后的mapper,是我的mapper中的空间地址写错了呢

  9. less算宽度 加~ width: calc(~"50% - 35px");

    less算宽度 加~  width: calc(~"50% - 35px");

  10. 安卓获取数据demo出现的问题

    时间戳是long型的数据,但其他数据都是float型,但AsyncTask要求是统一数据类型.这样我就不能把时间戳放进AsyncTask里面进行处理,我就在doInBackground中获取时间戳然后 ...