jsパスワードの強弱を検証する小さい例

3358 ワード

ページコード:
 
  

       
       
   

           
               
                   
                   
                   
               
           

       

スタイル:
 
  

jsコード:
 
  
<br>        window.onload = function () { <br>            var textInput = document.getElementById("txtPwd"); <br>            // <br>            textInput.onkeyup = function () { <br>                var pwdValue = this.value; <br>                var num = pwdChange(pwdValue); <br>                var tds = document.getElementById("pwdLever").getElementsByTagName("td"); <br>                // <br>                if (num == 0 || num == 1) { <br>                    tds[0].style.backgroundColor = "red"; <br>                    tds[1].style.backgroundColor = "gray"; <br>                    tds[2].style.backgroundColor = "gray"; <br>                } <br>                else if (num == 2) { <br>                    tds[0].style.backgroundColor = "red"; <br>                    tds[1].style.backgroundColor = "red"; <br>                    tds[2].style.backgroundColor = "gray"; <br>                } <br>                else if (num == 3) { <br>                    tds[0].style.backgroundColor = "red"; <br>                    tds[1].style.backgroundColor = "red"; <br>                    tds[2].style.backgroundColor = "red"; <br>                } <br>                else { <br>                    tds[0].style.backgroundColor = "gray"; <br>                    tds[1].style.backgroundColor = "gray"; <br>                    tds[2].style.backgroundColor = "gray"; <br>                } <br>            } <br>        } <br>        function pwdChange(v) { <br>            var num = 0; <br>            var reg = /\d/; // <br>            if (reg.test(v)) { <br>                num++; <br>            } <br>            reg = /[a-zA-Z]/; // <br>            if (reg.test(v)) { <br>                num++; <br>            } <br>            reg = /[^0-9a-zA-Z]/; // <br>            if (reg.test(v)) { <br>                num++; <br>            } <br>            if (v.length < 6) { // 6 <br>                num--; <br>            } <br>            return num; <br>        } <br>