Javascripit Implement password strength detection code sharing

Source: Internet
Author: User

  This article mainly introduces the javascripit to achieve password strength detection, we refer to the use of the bar

  Code as follows: <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http:// "> <html xmlns=" ">   <head>     <meta http-equiv=" Content-type "content=" text/html; charset=gb2312 "/>     <title>         password strength test     </title>   & nbsp <style type= "Text/css" >         body{font:12px/1.5 Arial; width:150px;font-family:arial;border:1px         solid #ccc;p adding:3px;} input.correct{border:1px solid Green; input.error{border:1px         solid red; #tips {float:left; margin:2px 0 0 20px;} #tips span{float:left;width:50px;height:20px;color: #fff; Overflow:hidden;background: #ccc; margin-right:2px; Line-height:20px;text-align:center;}         #tips. S1. Active{background: #f30;} #tips. s2 active{background: #fc0;}#tips. S3        . Active{background: #cc0} #tips. S4 active{background: #090;}     </ style>     <script type= "Text/javascript" >         window.onload = function () {&NB Sp           var otips = document.getElementById ("Tips");             var oinput = document.getelementsbytagname ("input") [0];             var aspan = Otips.getelementsbytagname ("span");             var aStr = ["Weak", "medium", "strong", "very good"];             var i = 0;               Oinput.onkeyup = Oinput.onfocus = Oinput.onblur = function () {  &NB Sp             var index = Checkstrong (this.value);                 This.classname = index? "Correct": "Error";               &NBSP Otips.classname = "s" + index;                 for (i = 0; i < aspan.length; i++) Aspan[i].classname = Aspan[i ].innerhtml = "";                 Index && (aspan[index-1].classname = "active", Aspan[ind ex-1].innerhtml = astr[index-1])            }        };        /** strength rule             +----------------------------------------- --------------+             1) any combination of less than 6 characters, weak; the same character combination of any number of characters, weak;         &N Bsp   2 character combination of any number of characters, in             3) 12-digit characters below the three-or four-character combinations, strong;         & nbsp   4 12-bit characters above the three-or four-class character combinations, very good.             +-------------------------------------------------------+     &NBSP ;       **/       //Detection secretCode strength         function Checkstrong (svalue) {            var modes = 0; &n Bsp           if (Svalue.length < 6) return modes;             if (/d/.test (svalue)) modes++; Digital             if (/[a-z]/.test (svalue)) modes++; lowercase             if (/[a-z]/.test (svalue)) modes++; Capital               if (/w/.test (svalue)) modes++; Special characters             switch (modes) {            Case 1:                 return 1;                 break;             Case 2:                 2             Case 3:             Case 4:     &nbsp           return Svalue.length < 12? 3:4                 break;                     {    </script> </head> &nbs P <body>     <input type= "password" value= "maxlength=" "/>     <div id=" Tips "> &nb Sp       <span></span>         <span></span>         <span></span>         <span></span>     </div> </b ody>   </html>  
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.