教程集 www.jiaochengji.com
教程集 >  脚本编程  >  javascript  >  正文 js检测密码强度的代码(附效果图)

js检测密码强度的代码(附效果图)

发布时间:2015-01-26   编辑:jiaochengji.com
本文分享下,一段检测密码强度的js代码,使用js正则来进行验证,并附有效果图,有需要的朋友,可以参考下。

使用javascript代码检测密码的强度,效果图如下所示:
检测密码强度

1,js代码:

<script>
/**
* js 正则验证密码强度
* by www.jbxue.com
*/
function AuthPasswd(string) {
if(string.length >=6) {
if(/[a-zA-Z]+/.test(string) && /[0-9]+/.test(string) && /\W+\D+/.test(string)) {
noticeAssign(1);
}else if(/[a-zA-Z]+/.test(string) || /[0-9]+/.test(string) || /\W+\D+/.test(string)) {
if(/[a-zA-Z]+/.test(string) && /[0-9]+/.test(string)) {
noticeAssign(-1);
}else if(/\[a-zA-Z]+/.test(string) && /\W+\D+/.test(string)) {
noticeAssign(-1);
}else if(/[0-9]+/.test(string) && /\W+\D+/.test(string)) {
noticeAssign(-1);
}else{
noticeAssign(0);
}
}
}else{
noticeAssign(null);
}
}

function noticeAssign(num) {
if(num == 1) {
$('#weak').css({backgroundColor:'#009900'});
$('#middle').css({backgroundColor:'#009900'});
$('#strength').css({backgroundColor:'#009900'});
$('#strength').html('很强');
$('#middle').html('');
$('#weak').html('');
}else if(num == -1){
$('#weak').css({backgroundColor:'#ffcc33'});
$('#middle').css({backgroundColor:'#ffcc33'});
$('#strength').css({backgroundColor:''});
$('#weak').html('');
$('#middle').html('中');
$('#strength').html('');
}else if(num ==0) {
$('#weak').css({backgroundColor:'#dd0000'});
$('#middle').css({backgroundColor:''});
$('#strength').css({backgroundColor:''});
$('#weak').html('弱');
$('#middle').html('');
$('#strength').html('');
}else{
$('#weak').html('&nbsp;');
$('#middle').html('&nbsp;');
$('#strength').html('&nbsp;');
$('#weak').css({backgroundColor:''});
$('#middle').css({backgroundColor:''});
$('#strength').css({backgroundColor:''});
}
}
</script>

您可能感兴趣的文章:
js检测密码强度的代码(附效果图)
JS检测密码强度(密码过短、密码强度良好、密码强度高)
Js用户注册时的密码强度提示代码
javascript 密码强度检测效果
jQuery密码强度提示插件 Complexify
passwordStrength 基于jquery的密码强度检测代码使用介绍
密码强度检测代码
php 密码强度检测代码
js验证密码强度的一段代码(图文)
js 验证密码强度的例子

[关闭]
~ ~