密码强度显示和中文强弱显示
复制代码代码如下:
<!doctype html公共” - // W3C // DTD HTML 4.01 Transitional // en>
<html>
<头>
<base href =“ <%= basepath%>”>
<title>我的JSP'a.jsp'启动页</title>
<meta http-equiv =“ pragma” content =“ no-cache”>
<meta http-equiv =“ cache-control” content =“ no-cache”>
<meta http-equiv =“ expires” content =“ 0”>
<meta http-equiv =“关键字” content =“ keyword1,keyword2,keyword3”>
<meta http-equiv =“描述” content =“这是我的页面”>
<style type =“ text/css”>
* {margin:0px; padding:0px;}
。
。
.status-bar跨度{背景色:#42bf26;高度:5px; display:inline-block;}
</style>
</head>
<身体>
<input type =“密码” id =“ pwd1” style =“ float:left; sumgin-top:5px;” onKeyup =“ checkpassword();”/>
<div ID =“ p_passwordstatus”
style =“ display:none; width:300px;”>
<span>密码强度:</span>
<span style =“ text-indent:0px;”>
<span style =“ line-height:5px;”> </span>
</span>
<span> </span>
</div>
</body>
</html>
<script type =“ text/javascript” src =“ jquery-1.7.2.2.min.js”> </script>
<脚本类型=“ text/javascript”>
函数checkpassword(){
var pwd = $(“#pwd1”)。val();
gpasswdstatus(pwd,'p_passwordstatus');
}
函数gpasswdstatus(value,id){
var status = $(“#”+id);
变量结果= $(“#”+id).find(“。status-result”)[0];
var bar = $(“#”+id).find(“。status-bar span”);
if(value ===“”){
status.css(“显示”,“无”);
} 别的 {
var分数= gcheckpassword(value);
bar.css(“宽度”,得分 +“%”);
var resultdesp = ggetResultDesp(score);
result.innerhtml = resultdesp;
status.css(“显示”,“ block”);
}
}
/**
*检验密码强度并返回得分
*
* @param {}
* 密码
* @return {number}
*/
函数gcheckpassword(密码){
var _score = 0;
如果(!密码){
返回0
}
如果(password.length <= 4){
_Score += 5
} 别的 {
if(password.length> = 5 && password.length <= 7){
_Score += 10
} 别的 {
如果(password.length> = 8){
_Score += 25
}
}
}
var _uppercount =(password.match(/[az]/g)|| [])。长度;
var _lowerCount =(password.match(/[az]/g)|| [])。长度;
var _loweruppercount = _uppercount + _lowerCount;
if(_uppercount && _lowerCount){
_score += 20
} 别的 {
如果(_uppercount || _lowerCount){
_Score += 10
}
}
var _numberCount =(password.match(/[/d]/g,“”)|| [])。长度;
if(_numberCount> 0 && _numbercount <= 2){
_Score += 10
} 别的 {
如果(_numberCount> = 3){
_score += 20
}
}
var _CharacterCount =(password.match(/[!@#j #jumpimund; _/./--〜]/g)/g)|| [])。
if(_CharacterCount == 1){
_Score += 10
} 别的 {
如果(_CharacterCount> 1){
_Score += 25
}
}
if(_numberCount &&(_uppercount && _lowerCount)
&& _CharacterCount){
_Score += 5
} 别的 {
if(_numberCount && _loweruppercount && _ CharacterCount){
_Score += 3
} 别的 {
if(_numberCount && _loweruppercount){
_Score += 2
}
}
}
返回_Score
}
/**
*根据密码强度得分返回密码强弱度中文提示
*
* @param {}
* 分数
* @return {string}
*/
函数ggetResultdesp(score){
如果(得分<= 5){
返回“/u592a/u77ed”
} 别的 {
如果(得分> 5 &&分数<20){
返回“/u5f31”
} 别的 {
如果(得分> = 20 &&分数<60){
返回“/u4e2d”
} 别的 {
如果(得分> = 60){
返回“/u5f3a”
} 别的 {
返回 ””
}
}
}
}
}
</script>
以上所述就是本文给大家分享的全部内容了,希望对大家熟练掌握javascript能够有所帮助。