Regular Expressions for JS password Strength Verification (simple and easy to use) and js Regular Expressions

Source: Internet
Author: User

Regular Expressions for JS password Strength Verification (simple and easy to use) and js Regular Expressions

I have been working on a pass project recently. In the registration module, the password strength (low and medium) needs to be displayed when I enter the password ). Today, I will share with you the results. The code is not as complex as searching on the Internet and can meet general requirements.

The html code is as follows:

<! Doctype html> 

The js Code is 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', 'zhong', '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 = 'stringthlv '+ lv; this. oStrengthTxt. innerHTML = aLvTxt [lv];};

:

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 strip.

2. You can customize password strength rules in the checkStrength method.

3. Three css styles (strengthLv1, strengthLv2, and strengthLv3) are displayed at a low and medium level ).

The above is a regular expression for JS password Strength Verification introduced by xiaobian. I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.