JS Test Password strength (low medium High) drawing _javascript tips

Source: Internet
Author: User
Recently has been doing a pass project, inside the registration module to enter the password required to display the password strength (low to high). Today to do the effect of sharing, the code is not online search so complex, to meet the general needs.

The HTML code is as follows:
Copy Code code as follows:

<! DOCTYPE html>
<meta charset= "Utf-8"/>
<title> Password Strength </title>
<style type= "Text/css" >
#passStrength {height:6px;width:120px;border:1px solid #ccc;p adding:2px;}
. strengthlv1{background:red;height:6px;width:40px;}
. strengthlv2{background:orange;height:6px;width:80px;}
. strengthlv3{background:green;height:6px;width:120px;}
</style>
<body>
<input type= "password" name= "pass" id= "pass" maxlength= "/>"
<div class= "Pass-wrap" >
<em> Password Strength:</em>
<div id= "Passstrength" ></div>
</div>
</body>
<script type= "Text/javascript" src= "Js/passwordstrength.js" ></script>
<script type= "Text/javascript" >
New Passwordstrength (' Pass ', ' passstrength ');
</script>

The JS code is as follows:
Copy Code code 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 ', ' Medium ', ' 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 = ' strengthlv ' + LV;
This.oStrengthTxt.innerHTML = Alvtxt[lv];
};

Effect Chart:

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 Checkstrength method can customize the rules of password strength.

3, the intensity of the password display low and high 3 CSS styles (strengthLv1, STRENGTHLV2, StrengthLv3) respectively.

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.