欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JS利用正則表達(dá)式實(shí)現(xiàn)簡(jiǎn)單的密碼強(qiáng)弱判斷實(shí)例

 更新時(shí)間:2017年06月16日 10:50:59   作者:小魚小魚加油吐泡泡  
這篇文章主要給大家介紹了關(guān)于JS利用正則表達(dá)式實(shí)現(xiàn)簡(jiǎn)單的密碼強(qiáng)弱判斷的相關(guān)資料,實(shí)現(xiàn)后的效果非常簡(jiǎn)單,但也挺實(shí)用的,文中給出了詳細(xì)的示例代碼供大家參考學(xué)習(xí),需要的朋友們下面來一起看看吧。

實(shí)現(xiàn)功能:

1、輸入字符要在6-16之間;小于6個(gè)字符或大于16個(gè)字符時(shí)給予提示,而且強(qiáng)弱不顯示;為0時(shí),也給予提示;

2、當(dāng)密碼在6-16個(gè)字符之間時(shí),如果密碼全是數(shù)字或全是字母,顯示弱;密碼是數(shù)字與字母的組合,則顯示強(qiáng);若為字母數(shù)字加下劃線,則為強(qiáng);

效果圖如下:

 代碼如下:

<!DOCTYPE html>
<html>
 <head>
 <meta charset="utf-8">
 <title></title>
 <style>
  .mm-body{
  position: relative;
  height: 100px;
  width: 450px;
  background-color: wheat;
  }
  .mm-top{
  height:35px;
  width: 450px;
  background-color: wheat;
  }
  .mm-sr{
  height:30px;
  width: 100px; 
  float: left;
  text-align: center; 
  line-height: 30px;
  }
  #mm-pwd{
  float: left;
  height:25px;
  background-color: ghostwhite;
  border-radius: 5px; 
  width: 150px;
  }
 .mm-btm{
  height: 40px;
  width: 140px;
  position: relative;
  margin-left: 110px;
  }
 #lv1,#lv2,#lv3{
  height: 30px;
  width: 40px;
  border-top: 4px solid gainsboro; 
  margin-left: 3px;
  float: left;
  font-size: 18px;
  text-align: center;
  line-height: 25px;
  }
 </style>
 </head>
 
 <body>
 <div class="mm-body">
  <div class="mm-top">
  <span class="mm-sr">請(qǐng)輸入密碼:</span>
  <form method="get" action="data.html" >
  <input type="password" id="mm-pwd" onkeyup="show()"/>
  </form>
  <span id="mm-pd"style="color: red; font-size: 12px; line-height: 30px;"></span>
  </div>
  <div class="mm-btm">
  <div id="lv1">弱</div>
  <div id="lv2">中</div>
  <div id="lv3">強(qiáng)</div>
  
 <!--強(qiáng)度判斷也可用表格做
  <table border="0px" cellpadding="0px" cellspacing="1px" >
  <tr height="20px" >
   <td width="40px" id="lv1" style="border-top: 3px solid darkgrey;">弱</td>
   <td width="40px" id="lv2" style="border-top: 3px solid darkgrey;">中</td>
   <td width="40px" id="lv3" style="border-top: 3px solid darkgrey;">強(qiáng)</td>
  </tr>
  </table>-->
  
  
  </div>
 </div>
 </body>
</html>
<script language="JavaScript">
function show(){
 var a=document.getElementById("mm-pwd").value;
 
 if(a.length==0){
 document.getElementById("mm-pd").innerHTML="密碼不能為空!"; 
 }
 else if(a.length<6){
 document.getElementById("mm-pd").innerHTML="密碼長(zhǎng)度小于6個(gè)字符!"; 
 }
 
 else if(a.length>=6&&a.length<=16){
  document.getElementById("mm-pd").innerHTML="";
 var reg=/^[0-9]{6,16}$|^[a-zA-Z]{6,16}$/; //全是數(shù)字或全是字母 6-16個(gè)字符
 var reg1=/^[A-Za-z0-9]{6,16}$/; //數(shù)字、26個(gè)英文字母 6-16個(gè)字符
 var reg2=/^\w{6,16}$/;  // 由數(shù)字、26個(gè)英文字母或者下劃線組成的字符串 6-16個(gè)字符
  if(a.match(reg)){
   document.getElementById("lv1").style.borderTopColor="red"; 
  
   }
  else if(a.match(reg1)){
  document.getElementById("lv1").style.borderTopColor="red"; 
   document.getElementById("lv2").style.borderTopColor="yellow"; 
  }
  else if(a.match(reg2)){
  document.getElementById("lv1").style.borderTopColor="red";
   document.getElementById("lv2").style.borderTopColor="yellow";
   document.getElementById("lv3").style.borderTopColor="green"; 
  }
  }
 
 else if(a.length>16){
 document.getElementById("mm-pd").innerHTML="密碼長(zhǎng)度大于16個(gè)字符!";
 document.getElementById("lv1").style.borderTopColor="gainsboro";
 document.getElementById("lv2").style.borderTopColor="gainsboro";
 document.getElementById("lv3").style.borderTopColor="gainsboro";
 }
 
 }
 
</script>

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對(duì)腳本之家的支持。

相關(guān)文章

最新評(píng)論