网上转载的一段代码,留着以后用,

js文件:

//判断输入密码的类型
function CharMode(iN){
if (iN>=48 && iN <=57) //数字
return 1;
if (iN>=65 && iN <=90) //大写
return 2;
if (iN>=97 && iN <=122) //小写
return 4;
else
return 8;
}
//bitTotal函数
//计算密码模式
function bitTotal(num){
modes=0;
for (i=0;i<4;i++){
if (num & 1) modes++;
num>>>=1;
}
return modes;
}
//返回强度级别
function checkStrong(sPW){
if (sPW.length<=4)
return 0; //密码太短
Modes=0;
for (i=0;i<sPW.length;i++){
//密码模式
Modes|=CharMode(sPW.charCodeAt(i));
}
return bitTotal(Modes);
}

//显示颜色
function pwStrength(pwd){
O_color="#eeeeee";
L_color="#FF0000";
M_color="#FF9900";
H_color="#33CC00";
if (pwd==null||pwd==''){
Lcolor=Mcolor=Hcolor=O_color;
}
else{
S_level=checkStrong(pwd);
switch(S_level) {
case 0:
Lcolor=Mcolor=Hcolor=O_color;
case 1:
Lcolor=L_color;
Mcolor=Hcolor=O_color;
break;
case 2:
Lcolor=Mcolor=M_color;
Hcolor=O_color;
break;
default:
Lcolor=Mcolor=Hcolor=H_color;
}
}
document.getElementById("strength_L").style.background=Lcolor;
document.getElementById("strength_M").style.background=Mcolor;
document.getElementById("strength_H").style.background=Hcolor;
return;
}

页面:

<td>
<table border="0"><tr >
<td style=" padding: 0px;border-top-width: 0px; border-right: #ff0000 0px solid; border-left: #ff0000 0px solid; border-top-color: #ff0000; border-bottom: #ff0000 0px solid;">

<input id="password"name="password" type=password size=8 onKeyUp=pwStrength(this.value) onBlur=pwStrength(this.value)></td>
<td style=" padding: 0px;border-top-width: 0px; border-right: #ff0000 0px solid; border-left: #ff0000 0px solid; border-top-color: #ff0000; border-bottom: #ff0000 0px solid;">
<span id="sp_6" style="color:red;" ></span>
</td>
<td style=" padding: 0px;border-top-width: 0px; border-right: #ff0000 0px solid; border-left: #ff0000 0px solid; border-top-color: #ff0000; border-bottom: #ff0000 0px solid;">
<table width="500" border="0" cellspacing="0" cellpadding="1" bordercolor="#eeeeee" height="20" style='display:inline'>
<tr align="center" bgcolor="#f5f5f5">
<td width="33%" id="strength_L">弱</td>
<td width="33%" id="strength_M">中</td>
<td width="33%" id="strength_H">强</td>
</tr>
</table>
</td>
</tr>
</table>
</td>

js校验密码强度的更多相关文章

  1. 正则表达式之js检验密码强度

    最近一直在做通行证项目,里面的注册模块中输入密码需要显示密码强度(低中高).今天就把做的效果给大家分享下,代码没有网上搜索的那么复杂,能够满足一般的需求. html 代码如下: <!DOCTYP ...

  2. js判断密码强度

    html代码: <form name="form1" action=""> 密码:<input type="password&quo ...

  3. js 检验密码强度

    html 代码如下: <!DOCTYPE HTML> <html lang="en"> <head> <meta charset=&quo ...

  4. js实现密码强度验证

    <html> <head> <meta http-equiv="content-type" content="text/html" ...

  5. 【javascript】js 检验密码强度

    最近一直在做通行证项目,里面的注册模块中输入密码需要显示密码强度(低中高).今天就把做的效果给大家分享下,代码没有网上搜索的那么复杂,能够满足一般的需求. html 代码如下: <!DOCTYP ...

  6. js实现密码强度

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  7. Js判断密码强度并显示提示信息

    用javascipt实现的Ajax判断密码强弱的功能,大多数有用户注册功能的网站,都会有这么一个功能,作为WEB程序员,应该会写这种小模块哦,不懂的就看下这个例子,觉得挺简单,当初帮助了不少人学会了密 ...

  8. js判断密码强度是否符合

    /** 判断密码强度是否符合 */ function check_passwd_intensity(password) { value = $.trim(password); if( value.le ...

  9. js校验密码必须包含字母大小写、数字

    校验密码必须包含字母大小写.数字 function checkPasswordNew(s){ var str=trim(s); //var reg = /^(?![A-Z]+$)(?![a-z]+$) ...

随机推荐

  1. 本地缓存localstorage使用

    最近做项目遇到一个问题,即从“个人中心”点击进入“修改支付宝”,需要自动获取用户手机号怎么做? 修改支付宝的api不提供用户手机号数据,但是发现个人中心提供,于是想通过localstorage在个人中 ...

  2. javascript 对象属性的添加,删除,json对象和字符串转换方法等

    1:动态添加 对象属性 var obj = new Object(); console.log (obj.username); obj.username = "haha"; con ...

  3. AJAX enabled & disabled

    @model string           @{    ViewBag.Title = "GetPeople";    AjaxOptions ajaxOpts = new A ...

  4. Uncaught SyntaxError: Invalid Unicode escape sequence异常处理

    今天碰到一个问题,页面报错:Uncaught SyntaxError: Invalid Unicode escape sequence ,{index:'operate',name:'operate' ...

  5. Java里日期转换及日期比较大小

    1.比较日期的大小: DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//创建日期转换对象hh:mm:ss为 ...

  6. StreamingContext、DStream、Receiver深度剖析

    本课分成四部分讲解,第一部分对StreamingContext功能及源码剖析:第二部分对DStream功能及源码剖析:第三部分对Receiver功能及源码剖析:最后一部分将StreamingConte ...

  7. xpath节点匹配简易教程

    2017-03-23 非本人原创,只是写爬虫时很有用,就留下了 <A id="a1"> <B id="b1"> <C id=&qu ...

  8. UI_UITableView_搭建

    创建 tableView UITableViewStyle 有两种选择 #pragma mark - 创建 tableView - (void)createTableView { // 枚举类型共同拥 ...

  9. Visual Studio 2015 Update 1 安装到最后 KB3022398 错误解决方法

    最后一步遇到一个错误的确让人心寒 只是我们还是得一步步解决.别去卸载重装.太费时 首先打开 regedit 注冊表,依次进入: 1:HKEY_LOCAL_MACHINE\SOFTWARE\Micros ...

  10. SVN 权限配置详解

    SVN权限详细配置 本章将详细介绍SVN权限配置涉及的两个配置文件, svnserve.conf 和 authz.conf,通过对配置逐行的描述,来阐明其中的一些细节含义.除此之外的其他配置.安装等内 ...