密码强度显示和中文强弱显示 复制代码 代码如下: My JSP 'a.jsp' starting page <br /> * {margin:0px;padding:0px;}<br /> .J_PasswordStatus{padding-bottom:0px;height:18px;}<br /> .status-bar{margin:0px;display:inline-block;width:80px;height:5px;padding:1px;border:1px solid #42BF26;background-color:white;vertical-align:middle;font-size:0;}<br /> .status-bar span{background-color:#42BF26;height:5px;display:inline-block;}<br /> style="display: none; width: 300px;"> 密码强度: <br /> function checkPassword(){<br /> var pwd = $("#pwd1").val();<br /> gPasswdStatus(pwd,'p_PasswordStatus');<br /> }<br /> function gPasswdStatus(value,id){<br /> var status = $("#"+id);<br /> var result = $("#"+id).find(".status-result")[0];<br /> var bar = $("#"+id).find(".status-bar span");<br /> if (value === "") {<br /> status.css("display","none");<br /> } else {<br /> var score = gCheckPassword(value);<br /> bar.css("width",score + "%");<br /> var resultDesp = gGetResultDesp(score);<br /> result.innerHTML = resultDesp;<br /> status.css("display","block");<br /> }<br /> }<br /> /**<br /> * 检验密码强度并返回得分<br /> * <br /> * @param {}<br /> * password<br /> * @return {Number}<br /> */<br /> function gCheckPassword(password) {<br /> var _score = 0;<br /> if (!password) {<br /> return 0<br /> }<br /> if (password.length <= 4) {<br /> _score += 5<br /> } else {<br /> if (password.length >= 5 && password.length <= 7) {<br /> _score += 10<br /> } else {<br /> if (password.length >= 8) {<br /> _score += 25<br /> }<br /> }<br /> }<br /> var _UpperCount = (password.match(/[A-Z]/g) || []).length;<br /> var _LowerCount = (password.match(/[a-z]/g) || []).length;<br /> var _LowerUpperCount = _UpperCount + _LowerCount;<br /> if (_UpperCount && _LowerCount) {<br /> _score += 20<br /> } else {<br /> if (_UpperCount || _LowerCount) {<br /> _score += 10<br /> }<br /> }<br /> var _NumberCount = (password.match(/[\d]/g, "") || []).length;<br /> if (_NumberCount > 0 && _NumberCount <= 2) {<br /> _score += 10<br /> } else {<br /> if (_NumberCount >= 3) {<br /> _score += 20<br /> }<br /> }<br /> var _CharacterCount = (password.match(/[!@#$%^&*?_\.\-~]/g) || []).length;<br /> if (_CharacterCount == 1) {<br /> _score += 10<br /> } else {<br /> if (_CharacterCount > 1) {<br /> _score += 25<br /> }<br /> }<br /> if (_NumberCount && (_UpperCount && _LowerCount)<br /> && _CharacterCount) {<br /> _score += 5<br /> } else {<br /> if (_NumberCount && _LowerUpperCount && _CharacterCount) {<br /> _score += 3<br /> } else {<br /> if (_NumberCount && _LowerUpperCount) {<br /> _score += 2<br /> }<br /> }<br /> }<br /> return _score<br /> }<br /> /**<br /> * 根据密码强度得分返回密码强弱度中文提示<br /> * <br /> * @param {}<br /> * score<br /> * @return {String}<br /> */<br /> function gGetResultDesp(score) {<br /> if (score <= 5) {<br /> return "\u592a\u77ed"<br /> } else {<br /> if (score > 5 && score < 20) {<br /> return "\u5f31"<br /> } else {<br /> if (score >= 20 && score < 60) {<br /> return "\u4e2d"<br /> } else {<br /> if (score >= 60) {<br /> return "\u5f3a"<br /> } else {<br /> return ""<br /> }<br /> }<br /> }<br /> }<br /> }<br /> 以上所述就是本文给大家分享的全部内容了,希望对大家熟练掌握javascript能够有所帮助。