Verify the password strength of js on the client, and be compatible with FireFox and IE_javascript skills

Source: Internet
Author: User
Verify the password strength of js on the client and be compatible with FireFox and IE

<Script language = "JavaScript"> function EvaluatePassword (word) {if (word = ") {return 0;} else if (word. length <6) {return 1;} else {return word. match (/[a-z] (?! [^ A-z] * [a-z]) | [A-Z] (?! [^ A-Z] * [A-Z]) | \ d (?! [^ \ D] * \ d) | [^ a-zA-Z \ d] (?! [A-zA-Z \ d] * [^ a-zA-Z \ d])/g ). length ;}} var test = new Array ("", "a1 _", "abcdef", "abcde123", "ads23 %", "aA1B2 ^ & 2 "); for (var I in test) {document. the password strength of write (test [I] + "is" + EvaluatePassword (test [I]) + "");} script
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]


Just change it to this ......

Password: <input id = "txt" onblur = "ck (this. value) "> <label id = n> </label> script function ck (t) {n. innerText = /(? : ^ (W) 1 {0, 8} $) | ^ (? :( 0? 1? 2? 3? 4? 5? 6? 7? 8? 9? 0 ?) 2? $) | ^ W {0, 6} $/I. test (t )? 'Too easy ': 'Okay';} script
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]


Google Effect

<Script language = javascript> // CharMode function // test the type of a character. function CharMode (iN) {if (iN> = 48 & iN <= 57) // number return 1; if (iN> = 65 & iN <= 90) // capital letter return 2; if (iN> = 97 & iN <= 122) // lower case return 4; else return 8; // special character} // bitTotal function // calculate the total number of modes in the current password: function bitTotal (num) {modes = 0; for (I = 0; I <4; I ++) {if (num & 1) modes ++; num >>>= 1;} return modes ;} // checkStrong function // return the password strength level function checkStrong (sPW) {if (sPW. length <= 4) return 0; // The password is too short. Modes = 0; for (I = 0; I <sPW. length; I ++) {// test the category of each character and count the total number of modes. modes | = CharMode (sPW. charCodeAt (I);} return bitTotal (Modes);} // pwStrength function // when the user releases the keyboard or the password input box loses focus, function pwStrength (pwd) {O_color = "# eeeeee"; L_color = "# FF0000"; M_color = "# FF9900 "; h_color = "#33CC00"; if (pwd = null | pwd = '') {Lcolor = Mcolor = Hcolor = O_color;} else {S_level = checkStrong (pwd ); switch (S_level) {case 0: Lcolor = Mcolor = Hcolor = O_color; case 1: Lcolor = L_color; Mcolor = Hcolor = O_color; break; case 2: Lcolor = Mcolor = M_color; hcolor = O_color; break; default: Lcolor = Mcolor = Hcolor = H_color;} document. getElementById ("strength_L "). style. background = Lcolor; document. getElementById ("strength_M "). style. background = Mcolor; document. getElementById ("strength_H "). style. background = Hcolor; return;} script
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

Related Article

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.