JavaScript Password Strength check code (two methods) _javascript tips

Source: Internet
Author: User

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

 <!doctype html>  

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.

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.