<!DOCTYPE html>
<html>
<head>
<title>密码强度校验</title>
<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
//jQuery内容
$(document).ready(function(){
$('#input').blur(function(event){
var password = $('#input').val();
function getValue(password){
var value = 0;
if(password.length>=8){
value = 1;
}
for(var i=0;i<password.length;i++){
var current = password.charCodeAt(i);
//大写或小写字母
if(((current>=65&¤t<=90)||(current>=97&¤t<=122))&&password.length>=8){
value = 2;
}
//特殊字符
if(((current>=33&¤t<=47)||(current>=58&¤t<=64)||(current>=91&¤t<=96)||(current>=123&¤t<=126))&&password.length>=8){
value = 3;
break;
}
}
return value;
}
var value = getValue(password);
if(value==0){
$('#show').text('低强度');
$('#show').css({'color':'red'});
}else if(value==1){
$('#show').text('中低强度');
$('#show').css({'color':'orange'});
}else if(value==2){
$('#show').text('中强度');
$('#show').css({'color':'blue'});
}else if(value==3){
$('#show').text('高强度');
$('#show').css({'color':'green'});
}
});
});
</script>
</head>
<body>
<input type="password" id="input">
<span id="show"></span>
</body>
</html>