JavaScript验证密码强度
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验证密码强度的更多相关文章
- JS简单验证密码强度
<input type="password" id="password" value=""/><button id=&qu ...
- javascript 检测密码强度
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- JavaScript判断密码强度
以下是代码: <html> <head> <title>JS判断密码强度</title> <script language=javascript& ...
- jquery用正则表达式验证密码强度
/** * 不加paste鼠标粘贴不起作用 * 不加input第一次粘贴的时候不变 * 加上input和focus可以兼容表情 * ke ...
- javascript 检测密码强度 美化版
模仿美团的美化 <!DOCTYPE> <head runat="server"> <title></title> <link ...
- MySQL密码强度验证修改
MySQL5.6.6版本之后增加了密码强度验证插件validate_password,相关参数设置的较为严格. 影响的语句和函数有:create user,grant,set password,pas ...
- 密码强度应用(js)
<!-- 密码强度div --> <div id="tips" class="help-block"> <b class=&quo ...
- JS简单验证password强度
<input type="password" id="password" value=""/><button id=&qu ...
- mysql 5.6密码强度插件使用
在mysql 5.6对密码的强度进行了加强,推出了validate_password 插件.支持密码的强度要求. 此插件要求版本:5.6.6 以上版本安装方式: 1.安装插件:(默认安装了插件后,强度 ...
随机推荐
- 系统中同时存在python2和python3时 pip有时候更新后会报错 解决安装的方法如下
官网原链接:https://pip.pypa.io/en/stable/installing/ Installation Do I need to install pip? pip is alread ...
- Android利用tcpdump抓包,用wireshark分析包。
1.前言 主要介绍在android手机上如何利用tcpdump抓包,用wireshark分析包. android tcpdump官网: http://www.androidtcpdump.com/ t ...
- Android屏幕适配-安卓切图
一.Android中的单位 1.dp(dip):density-independent pixels,这并不是一个绝对的单位,而只是一个相对的概念,代表的是屏幕写对角线上每inch上像素点的个数. 2 ...
- HDU 2828 Lamp 二分图的最大匹配 模型题
http://acm.hdu.edu.cn/showproblem.php?pid=2828 给定n个灯,m个开关,使得每栈灯亮,前提是控制这栈灯的开关的状态是其中一个.(题目应该都看得懂) 其实我想 ...
- CentOS 7.2安装pip
CentOS 7.2默认安装的python版本为python2.7.5,我的系统里面默认是没有安装pip 的,搜了下网上各路大侠的解决办法,如下: 使用yum安装python-pip,但是报错,说没有 ...
- HBase备份恢复练习
一.冷备 1.创建测试表并插入测试数据 [root@weekend05 ~]# hbase shell hbase(main):005:0> create 'scores','grade','c ...
- Properties没有被注意的地方
源起: 今天阅读源码时发现一个地方不理解: 为什么以下代码第10行 get() 之后value为null时还去 getProperty() 呢? org.springframework.util.Co ...
- CF962E Byteland, Berland and Disputed Cities
思路: http://codeforces.com/blog/entry/58869. 实现: #include <bits/stdc++.h> using namespace std; ...
- 日常博客----rem,em的恩怨相杀
基本知识: 使用 em 和 rem 单位可以让我们的设计更加灵活,能够控制元素整体放大缩小,而不是固定大小. 我们可以使用这种灵活性,使我们在开发期间,能更加快速灵活的调整,允许浏览器用户调整浏览器大 ...
- Python100天打卡-Day10-图形用户界面和游戏开发
基于tkinter模块的GUIPython默认的GUI开发模块是tkinter(在Python 3以前的版本中名为Tkinter)使用tkinter来开发GUI应用需要以下5个步骤: 导入tkinte ...