


Two methods for JS to implement password levels that contain at least letters, uppercase and lowercase numbers, and characters_javascript skills
The examples in this article describe two methods of using JS to implement password levels that contain at least letters, uppercase and lowercase numbers, and characters. Share it with everyone for your reference. The details are as follows:
Foreword
Passwords can be easily broken if they are set too simply, so many websites set very strict requirements for passwords, usually 2 out of 3 letters, numbers, and characters, and are case-sensitive. If the password is set too simple, an error message will be given. Or display the password level (low, medium and high) to allow users to set advanced passwords. So how to implement it using JS?
The implementation code is as follows:
function passwordLevel(password) { var Modes = 0; for (i = 0; i < password.length; i++) { Modes |= CharMode(password.charCodeAt(i)); } return bitTotal(Modes); //CharMode函数 function CharMode(iN) { if (iN >= 48 && iN <= 57)//数字 return 1; if (iN >= 65 && iN <= 90) //大写字母 return 2; if ((iN >= 97 && iN <= 122) || (iN >= 65 && iN <= 90)) //大小写 return 4; else return 8; //特殊字符 } //bitTotal函数 function bitTotal(num) { modes = 0; for (i = 0; i < 4; i++) { if (num & 1) modes++; num >>>= 1; } return modes; } }
Use
Normal use
Usage syntax: passwordLevel(string)
Validation rules: numbers, uppercase letters, lowercase letters, special characters
Function result: Returns the number of rules contained in the password
Running example:
passwordLevel("123456") //返回1 passwordLevel("Abc'123456") //返回4
Use in combination with jquery.validate.js:
//添加验证方法:至少包含两种规则 $.validator.addMethod("strongPsw",function(value,element){ if(passwordLevel(value)==1){returnfalse;} returntrue },"格式不符合"); //开始验证 $(".form").validate({ rules:{ pwd:{ required:true, //必填 minlength:6, //最小长度 maxlength:32, //最大长度 strongPsw:true, //密码强度 }, repwd:{ required:true, minlength:6, maxlength:32, equalTo:"#pwd" //再次填写密码需一致 } } });
Friends who are interested in password generation and strength detection can also refer to the online tool:
Password security online detection
Short link (short URL) online generation tool
I hope this article will be helpful to everyone’s JavaScript programming design.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics





Tomato Novel is a very popular novel reading software. We often have new novels and comics to read in Tomato Novel. Every novel and comic is very interesting. Many friends also want to write novels. Earn pocket money and edit the content of the novel you want to write into text. So how do we write the novel in it? My friends don’t know, so let’s go to this site together. Let’s take some time to look at an introduction to how to write a novel. Share the Tomato novel tutorial on how to write a novel. 1. First open the Tomato free novel app on your mobile phone and click on Personal Center - Writer Center. 2. Jump to the Tomato Writer Assistant page - click on Create a new book at the end of the novel.

When using Win11 system, sometimes you will encounter a prompt that requires you to enter the administrator username and password. This article will discuss how to deal with this situation. Method 1: 1. Click [Windows Logo], then press [Shift+Restart] to enter safe mode; or enter safe mode this way: click the Start menu and select Settings. Select "Update and Security"; select "Restart Now" in "Recovery"; after restarting and entering the options, select - Troubleshoot - Advanced Options - Startup Settings -&mdash

Unfortunately, people often delete certain contacts accidentally for some reasons. WeChat is a widely used social software. To help users solve this problem, this article will introduce how to retrieve deleted contacts in a simple way. 1. Understand the WeChat contact deletion mechanism. This provides us with the possibility to retrieve deleted contacts. The contact deletion mechanism in WeChat removes them from the address book, but does not delete them completely. 2. Use WeChat’s built-in “Contact Book Recovery” function. WeChat provides “Contact Book Recovery” to save time and energy. Users can quickly retrieve previously deleted contacts through this function. 3. Enter the WeChat settings page and click the lower right corner, open the WeChat application "Me" and click the settings icon in the upper right corner to enter the settings page.

1. Level 1 costs 0.5 yuan. 2. Level 2 costs 1 yuan. 3. Level 3 costs 2 yuan. 4. Level 4 costs 3 yuan. 5. Level 5 costs 5 yuan. 6. Level 6 costs 7 yuan. 7. Level 7 costs 9 yuan. 8. Level 8 costs 13 yuan. 9. Level 9 costs 18 yuan. 10. Level 10 costs 24 yuan. 11. Level 11 costs 32 yuan. 12. Level 12 costs 42 yuan. 13. Level 13 costs 57 yuan. 14. Level 14 costs 73 yuan. 15. Level 15 costs 97 yuan. 16. Level 16 costs 130 yuan.

Wireless networks have become an indispensable part of people's lives in today's digital world. Protecting the security of personal wireless networks is particularly important, however. Setting a strong password is key to ensuring that your WiFi network cannot be hacked by others. To ensure your network security, this article will introduce in detail how to use your mobile phone to change the router WiFi password. 1. Open the router management page - Open the router management page in the mobile browser and enter the router's default IP address. 2. Enter the administrator username and password - To gain access, enter the correct administrator username and password in the login page. 3. Navigate to the wireless settings page - find and click to enter the wireless settings page, in the router management page. 4. Find the current Wi

Wireless networks have become an indispensable part of our lives with the rapid development of the Internet. In order to protect personal information and network security, it is very important to change your wifi password regularly, however. To help you better protect your home network security, this article will introduce you to a detailed tutorial on how to use your mobile phone to change your WiFi password. 1. Understand the importance of WiFi passwords. WiFi passwords are the first line of defense to protect personal information and network security. In the Internet age, understanding its importance can better understand why passwords need to be changed regularly. 2. Confirm that the phone is connected to wifi. First, make sure that the phone is connected to the wifi network whose password you want to change before changing the wifi password. 3. Open the phone’s settings menu and enter the phone’s settings menu.

Mobile games have become an integral part of people's lives with the development of technology. It has attracted the attention of many players with its cute dragon egg image and interesting hatching process, and one of the games that has attracted much attention is the mobile version of Dragon Egg. To help players better cultivate and grow their own dragons in the game, this article will introduce to you how to hatch dragon eggs in the mobile version. 1. Choose the appropriate type of dragon egg. Players need to carefully choose the type of dragon egg that they like and suit themselves, based on the different types of dragon egg attributes and abilities provided in the game. 2. Upgrade the level of the incubation machine. Players need to improve the level of the incubation machine by completing tasks and collecting props. The level of the incubation machine determines the hatching speed and hatching success rate. 3. Collect the resources required for hatching. Players need to be in the game

Setting font size has become an important personalization requirement as mobile phones become an important tool in people's daily lives. In order to meet the needs of different users, this article will introduce how to improve the mobile phone use experience and adjust the font size of the mobile phone through simple operations. Why do you need to adjust the font size of your mobile phone - Adjusting the font size can make the text clearer and easier to read - Suitable for the reading needs of users of different ages - Convenient for users with poor vision to use the font size setting function of the mobile phone system - How to enter the system settings interface - In Find and enter the "Display" option in the settings interface - find the "Font Size" option and adjust it. Adjust the font size with a third-party application - download and install an application that supports font size adjustment - open the application and enter the relevant settings interface - according to the individual
