In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to achieve regular expressions that match numeric and alphabetic passwords. It is very detailed and has a certain reference value. Friends who are interested must read it!
The password for a user registration function has the following requirements: it consists of numbers and letters, and it should contain both numbers and letters, and the length should be between 8 and 16 digits.
How to analyze the requirements? Break it up! This is the general idea of software design. Therefore, the split requirements are as follows:
1, it can't be all numbers.
2, it can't be all letters
3, must be a number or letter
As long as you can meet the above three requirements at the same time, write as follows:
^ (?! [0-9] + $) (?! [a-zA-Z] + $) [0-9A-Za-z] {8jue 16} $
Let's comment separately:
^ matches the beginning of a line
(?! [0-9] + $) predict that the position is not all followed by numbers
(?! [a-zA-Z] + $) predicts that the position is not all followed by letters.
[0-9A-Za-z] {8001 16} consists of 8-16 digits or this letter
$match line end position
Note: (?! xxxx) is a form of negative zero width assertion of a regular expression that indicates that the position is not preceded by a xxxx character.
Test cases 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] {8regex 16} $"; String value = "aaa"; / / not long enough System.out.println (value.matches (regex)); value = "1111aaaa1111aaaaa"; / / too long System.out.println (value.matches (regex)) Value = "111111111"; / / Numeric System.out.println (value.matches (regex)); value = "aaaaaaaaa"; / / Pure letter System.out.println (value.matches (regex)); value = "# @ #"; / / Special character System.out.println (value.matches (regex)); value = "1111aaaa" / / numeric alphanumeric combination System.out.println (value.matches (regex)); value = "aaaa1111"; / / numeric alphanumeric combination System.out.println (value.matches (regex)); value = "aa1111aa"; / / numeric letter combination System.out.println (value.matches (regex)); value = "11aaaa11"; / / numeric letter combination System.out.println (value.matches (regex)) Value = "aa11aa11"; / / numeric and alphanumeric combination System.out.println (value.matches (regex));}} this is all about the article "how to implement regular expressions that match numeric and alphabetic passwords". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.