To register a new account on most platforms, entering a password is a must, and sometimes in order to remind the user to set a relatively secure password, the password strength is detected.
/** * @param input (password box) * @param notice (text hint) * Detect password strength for reference **/function checkpasswordstrength (input , notice) {var str = [' Password strength: weak ', ' Password strength: Medium ', ' Password strength: strong '],getstrength = function (str) {var strength = 0;if (Str.length < 6) return Strength;if (/\d/.test (str)) strength++; Digital if (/[a-z]/.test (str)) strength++; lowercase if (/[a-z]/.test (str)) strength++; Uppercase if (/\w/.test (str)) strength++; Special character switch (strength) {case 1:return 1;break;case 2:return 2;break;case 3:case 4:return str.length < 3:4break; }},strong;input.oninput = Input.onpropertychange = function () {strong = Getstrength (input.value); switch (strong {Case 0:notice.innerhtml = '; break;case 1:case 2:notice.innerhtml = str[0];break;case 3:notice.innerhtml = str[1]; Break;case 4:notice.innerhtml = Str[2];break;}}} Usevar input = document.getElementById (' password '), notice = document.getElementById (' notice '); Checkpasswordstrength (Input,notice);}
A very simple detection function, when the user input detection password whether there are numbers, lowercase letters, uppercase, special symbols, according to the input to determine the strength of the password.
It uses the event:oninput, Onpropertychange to listen for input box value changes.
Detect password strength