


A brief analysis of regular expressions for matching numeric and alphabetic passwords
I was working on a project recently and encountered such a requirement. It is required to be composed of numbers and letters, and it must contain both numbers and letters, and the length must be between 8-16 digits. Let me share with you the implementation code. Please take a look.
The password for a user registration function has the following requirements: it must be composed of numbers and letters, and it must contain both numbers and letters, and the length must be Between 8-16 bits.
How to analyze requirements? Split! This is the general idea of software design. So, the splitting requirements are as follows:
1, it cannot be all numbers
2, it cannot be all letters
3, it must be numbers or letters
As long as the above three requirements can be met at the same time, write it out as follows:
^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$
Comment it separately:
^ Match the beginning of a line
(?! [0-9]+$) Predict that the position is not followed by all numbers
(?![a-zA-Z]+$) Predict that the position is followed by not all letters
[0- 9A-Za-z] {8,16} consists of 8-16 digits or letters
$ Matches the end of the line position
Note: (?!xxxx) isRegular expression is a form of negative zero-width assertion, indicating that the character after the preset position is not xxxx.
The test examples are as follows:
public class Test { public static void main(String[] args) throws Exception { String regex = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$"; String value = "aaa"; // 长度不够 System.out.println(value.matches(regex)); value = "1111aaaa1111aaaaa"; // 太长 System.out.println(value.matches(regex)); value = "111111111"; // 纯数字 System.out.println(value.matches(regex)); value = "aaaaaaaaa"; // 纯字母 System.out.println(value.matches(regex)); value = "####@@@@#"; // 特殊字符 System.out.println(value.matches(regex)); value = "1111aaaa"; // 数字字母组合 System.out.println(value.matches(regex)); value = "aaaa1111"; // 数字字母组合 System.out.println(value.matches(regex)); value = "aa1111aa"; // 数字字母组合 System.out.println(value.matches(regex)); value = "11aaaa11"; // 数字字母组合 System.out.println(value.matches(regex)); value = "aa11aa11"; // 数字字母组合 System.out.println(value.matches(regex)); } }
The above is a regular expression introduced by the editor to match numeric and letter passwords. I hope it will be helpful to everyone. If you If you have any questions, please leave me a message and I will reply to you in time.
The above is the detailed content of A brief analysis of regular expressions for matching numeric and alphabetic passwords. For more information, please follow other related articles on the PHP Chinese website!

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

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

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.

This article will explore how to solve the problem of wrong password, especially the need to be careful when dealing with BitLocker warnings. This warning is triggered when an incorrect password is entered multiple times in BitLocker to unlock the drive. Usually, this warning occurs because the system has a policy that limits incorrect login attempts (usually three login attempts are allowed). In this case, the user will receive an appropriate warning message. The complete warning message is as follows: The password entered is incorrect. Please note that continuously entering incorrect passwords will cause the account to be locked. This is to protect the security of your data. If you need to unlock your account, you will need to use a BitLocker recovery key. The password is incorrect, beware the BitLocker warning you receive when you log in to your computer

Subtitles not working on Stremio on your Windows PC? Some Stremio users reported that subtitles were not displayed in the videos. Many users reported encountering an error message that said "Error loading subtitles." Here is the full error message that appears with this error: An error occurred while loading subtitles Failed to load subtitles: This could be a problem with the plugin you are using or your network. As the error message says, it could be your internet connection that is causing the error. So please check your network connection and make sure your internet is working properly. Apart from this, there could be other reasons behind this error, including conflicting subtitles add-on, unsupported subtitles for specific video content, and outdated Stremio app. like

1. Download and install Xiaobai’s one-click system reinstallation tool on another computer, insert an empty USB disk to create a USB boot disk. For specific tutorials, please refer to: 2. Insert the USB boot disk into the computer that needs to change the password to restart, and press Start hotkey. Generally, the startup hotkey is one of F12, F8, F9, F10, and ESC. Then the startup interface appears, select the option of the USB disk and press Enter to enter. 3. Select [1] to start win10x64PE and press Enter to confirm. 4. Select the password modification tool on the desktop and double-click to open it. 5. Then a list of account names appears, select the account that needs to change the password and open it. 6. Click the Change Password command below, enter the new password twice, and then click OK to save the changes. 7. Finally, unplug the USB flash drive and restart the computer. Then it will be normal.

Wireless networks have become an integral part of people's lives in modern society. Or need to view saved passwords in WiFi list, sometimes we forget WiFi password, however. Mobile software came into being to solve this problem. To make it easy for you to master this magical tool, this article will introduce a software that can help you quickly unlock all WiFi passwords. 1. Powerful WiFi password unlocking tool - explore the wonderful world of WiFi password unlocking 2. Simple and easy-to-use interface design - convenient and fast operation methods 3. Supports multiple devices - meets the needs of different devices 4. Automatically Update - always keep the latest WiFi password 5. High-speed WiFi connection - easily cope with the simultaneous connection needs of multiple devices

Analysis of user password storage mechanism in Linux system In Linux system, the storage of user password is one of the very important security mechanisms. This article will analyze the storage mechanism of user passwords in Linux systems, including the encrypted storage of passwords, the password verification process, and how to securely manage user passwords. At the same time, specific code examples will be used to demonstrate the actual operation process of password storage. 1. Encrypted storage of passwords In Linux systems, user passwords are not stored in the system in plain text, but are encrypted and stored. L
