Regular Expressions for JS password Strength Verification (simple and easy to use) and js Regular Expressions
I have been working on a pass project recently. In the registration module, the password strength (low and medium) needs to be displayed when I enter the password ). Today, I will share with you the results. The code is not as complex as searching on the Internet and can meet general requirements.
The html code is as follows:
<! Doctype html>
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. parentNode. appendChild (strong) ;}; PasswordStrength. prototype. checkStrength = function (val) {var aLvTxt = ['', 'low', 'zhong', 'high']; var lv = 0; if (val. match (/[a-z]/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 = 'stringthlv '+ lv; this. oStrengthTxt. innerHTML = aLvTxt [lv];};
:
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 strip.
2. You can customize password strength rules in the checkStrength method.
3. Three css styles (strengthLv1, strengthLv2, and strengthLv3) are displayed at a low and medium level ).
The above is a regular expression for JS password Strength Verification introduced by xiaobian. I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!