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. LPS UVA 11404 Palindromic Subsequence

    题目传送门 题意:求LPS (Longest Palidromic Subsequence) 最长回文子序列.和回文串不同,子序列是可以不连续的. 分析:1. 推荐->还有一种写法是用了LCS的 ...

  2. linux常用的shell命令

    1.shell介绍 shell(外壳)是linux系统的最外层,简单的说,它就是用户和操作系统之间的一个命令解释器. 2.shell命名的使用 ls :查看当前目录的信息,list .        ...

  3. 区间dp实战练习

    题解报告:poj 2955 Brackets(括号匹配) Description We give the following inductive definition of a “regular br ...

  4. hbuilder 中文乱码

    这是因为HBuilder默认文件编码是UTF-8,你可以在工具-选项-常规-工作空间选项中设置默认字符编码

  5. HDU 4565 So Easy! 数学 + 矩阵 + 整体思路化简

    http://acm.hdu.edu.cn/showproblem.php?pid=4565 首先知道里面那个东西,是肯定有小数的,就是说小数部分是约不走的,(因为b限定了不是一个完全平方数). 因为 ...

  6. Nginx缓存[proxy cache、memcache]

    nginx自带缓存 nginx自己有单独的进程来对磁盘上的缓存文件进行扫描,在内存中建立缓存索引.并且有管理进程来对缓存进行过期判断,更新等操作 定义:只能在http段中使用 proxy_cache_ ...

  7. mysql replication错误常见处理

    大部分的错误,都是日志错误 日志本身的错误 主日志和中继日志都可能出错,可以使用mysqlbinlog来读一下mysqlbinlog mysql-bin.000007>/dev/null ##只 ...

  8. 【转】数据库CRUD操作

    数据库CRUD操作 一.删除表   drop table 表名称 二.修改表 alter   table 表名称 add  列名 数据类型   (add表示添加一列) alter  table  表名 ...

  9. Hibernate懒加载深入分析

    Hibernate懒加载深入分析 懒加载可以提高性能吗?  不可以简单的说"能",因为Hibernate的关系映射拖累了SQL的性能,所以想出懒加载来弥补.只是弥补而以,不会超越. ...

  10. IOS的水滴文件效果

    @implementation ViewController - (void)viewDidLoad{ [super viewDidLoad]; NSDictionary *dict = [NSDic ...