Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Regular expression of JS password strength check

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "the regular expression of JS password strength check". In the daily operation, I believe that many people have doubts about the regular expression of JS password strength check. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "regular expression of JS password strength check". Next, please follow the editor to study!

The html code is as follows:

Password strength # passStrength {height:6px;width:120px;border:1px solid # ccc;padding:2px;} .strengthLv1 {background:red;height:6px;width:40px;} .strengthLv2 {background:orange;height:6px;width:80px;} .strengthLv3 {background:green;height:6px;width:120px;} password strength: new PasswordStrength ('pass','passStrength')

The js code is as follows:

Function PasswordStrength (passwordID,strengthID) {this.init (strengthID); var _ this = this; document.getElementById (passwordID). Onkeyup = function () {_ this.checkStrength (this.value);}}; PasswordStrength.prototype.init = function (strengthID) {var id = document.getElementById (strengthID); var div = document.createElement ('div'); var strong = document.createElement (' strong'); this.oStrength = id.appendChild (div); this.oStrengthTxt = id [XSS _ clean] .appendChild (strong);} PasswordStrength.prototype.checkStrength = function (val) {var aLvTxt = ['', 'low', 'medium', 'high']; var lv = 0; if (val.match (/ [Amurz] / g)) {lv++;} if (val.match (/ [0-9] / g)) {lv++;} if (val.match (/. [^ a-z0-9]) / g)) {lv++;} if (val.length)

< 6){lv=0;} if(lv >

3) {lv=3;} this.oStrength.className = 'strengthLv' + lv; this.oStrengthTxt [XSS _ clean] = aLvTxt [lv];}

Effect picture:

Instructions for use:

1. The first parameter of the object is the id of the password input box, and the second parameter is the id of the password strength bar.

2. The rules of password strength can be customized in the checkStrength method.

3. Password strength shows that low, medium and high correspond to three css styles (strengthLv1, strengthLv2, strengthLv3).

At this point, the study of "regular expression for JS password strength check" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report