First look at the effect of the picture:
JavaScript Password Strength Check code, the specific implementation of the idea is not much to say, please see the following code and demo.
The first method:
* * Password security
*return: All letters or numbers, or password length less than
*return: alphanumeric composition, or special characters, or numbers and special characters
*return: Letters and numbers and special characters
*/
String.prototype.passwordstrength=function () {
if (this.length> && this.length<=) return;
var n = (This.search (/[a-za-z]/)!=-)? :,
n = (this.search (/[-]/)!=-)?:,
n = (this.search (/[\~\ ' \!\@\#\$\%\^\&\*\ (\) \_\+\-\=\[\]|{ \}\;\ ' \:\ ' \,\.\/\<\>\?] {,}/) != -) ? : ;
return n+n+n;
}
Demo
The second method:
The JavaScript code is as follows:
<script> function authpasswd (string) {if (String.Length >=6) {if (/[a-za-z]+/.test (string) &&/[0-9]+/
. Test (String) &&/\w+\d+/.test (String)) {noticeassign (1); }else if (/[a-za-z]+/.test (string) | |/[0-9]+/.test (STRING) | |/\w+\d+/.test (STRING)) {if (/[a-za-z]+/.test (String) &
amp;&/[0-9]+/.test (String)) {noticeassign (-1);
}else if (/\[a-za-z]+/.test (String) &&/\w+\d+/.test (String)) {noticeassign (-1);
}else if (/[0-9]+/.test (String) &&/\w+\d+/.test (String)) {noticeassign (-1);
}else{noticeassign (0);
}}else{noticeassign (null);
} function noticeassign (num) {if (num = = 1) {$ (' #weak '). CSS ({backgroundcolor: ' #009900 '});
$ (' #middle '). CSS ({backgroundcolor: ' #009900 '});
$ (' #strength '). CSS ({backgroundcolor: ' #009900 '});
$ (' #strength '). html (' strong ');
$ (' #middle '). html (');
$ (' #weak '). html (');
}else if (num = = 1) {$ (' #weak '). CSS ({backgroundcolor: ' #ffcc33 '});
$ (' #middle '). CSS ({backgroundcolor: ' #ffcc33 '}); $('#strength '). CSS ({backgroundcolor: '});
$ (' #weak '). html (');
$ (' #middle '). html (' Medium ');
$ (' #strength '). html (');
}else if (num ==0) {$ (' #weak '). CSS ({backgroundcolor: ' #dd0000 '});
$ (' #middle '). CSS ({backgroundcolor: '});
$ (' #strength '). CSS ({backgroundcolor: '});
$ (' #weak '). html (' weak ');
$ (' #middle '). html (');
$ (' #strength '). html (');
}else{$ (' #weak '). html (' ');
$ (' #middle '). html (' ');
$ (' #strength '). html (' ');
$ (' #weak '). CSS ({backgroundcolor: '});
$ (' #middle '). CSS ({backgroundcolor: '});
$ (' #strength '). CSS ({backgroundcolor: '}); }} </script>
The above two ways to introduce the JavaScript password strength check code, I hope to help.