Home  >  Article  >  Web Front-end  >  jquery password strength verification_jquery

jquery password strength verification_jquery

WBOY
WBOYOriginal
2016-05-16 15:28:221326browse

本文实例讲述了jquery密码强度校验的验证代码,分享给大家供大家参考。具体如下:
预想的效果截图如下:

关键代码:

<script>
 
//下面的正则表达式建议各位收藏哦,项目上有可能会用得着
$(function(){  
  $('#pass').blur(function(e) {
    // alert('---------');
     //密码为八位及以上并且字母数字特殊字符三项都包括
     var strongRegex = new RegExp("^(&#63;=.{8,})(&#63;=.*[A-Z])(&#63;=.*[a-z])(&#63;=.*[0-9])(&#63;=.*\\W).*$", "g");
   
   //密码为七位及以上并且字母、数字、特殊字符三项中有两项,强度是中等 
     var mediumRegex = new RegExp("^(&#63;=.{7,})(((&#63;=.*[A-Z])(&#63;=.*[a-z]))|((&#63;=.*[A-Z])(&#63;=.*[0-9]))|((&#63;=.*[a-z])(&#63;=.*[0-9]))).*$", "g");
     var enoughRegex = new RegExp("(&#63;=.{6,}).*", "g");
     if (false == enoughRegex.test($(this).val())) {
         $('#passstrength').html('More Characters');
     } else if (strongRegex.test($(this).val())) {
         $('#passstrength').className = 'ok';
         $('#passstrength').html('Strong!');
     } else if (mediumRegex.test($(this).val())) {
         $('#passstrength').className = 'alert';
         $('#passstrength').html('Medium!');
     } else {
         $('#passstrength').className = 'error';
         $('#passstrength').html('Weak!');
     }
     return true;
  });
}); 
</script> 
         
<input type="password" name="pass" id="pass" /> 
<span id="passstrength"></span>

以上就是jquery判断密码强度校验代码,大家可以应用到自己的项目中,希望大家喜欢。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn