最新回應

Loading...

2014年3月17日 星期一

Lab 8 Using browsers for programming II

要求:撰寫一個網頁能夠自動檢查輸入的密碼,長度必須至少六個字元,且必須至少包含一個數字以及一個非英文字母的字元。


<html>
    <head>
    </head>
 <body id="body">
      <form action="javascript:void(0);" id="exampleForm">
      <input type="password" id="examplePass" />
   <input type="submit" />
      </form>
 </body>
 <script>

 document.getElementById("exampleForm").onsubmit = function() {
      //R
  
  
   var passwordRegex = /^(?=.*\d)(?=.*[\W_]).{6,}$/;
  
  
  
   if(!passwordRegex.test(document.getElementById("examplePass").value)){
        console.log("Regex didn't match");
     var notify = document.getElementById("notify");
     if(notify === null) {
        notify = document.createElement("p");
     notify.textContent = "密碼必須>=6 ,其中第一個字必須是數字,內部至少必須要有一個非英文的符號"
     notify.id = "notify";
    
     var body = document.getElementById("body");
     body.appendChild(notify);
   }
  }
 };
      </script>

 </html>










沒有留言:

張貼留言