In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how Java uses regular expressions to verify user names and passwords, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.
Request:
User name:
Must be 6-10 letters, numbers, underscores (where letters, numbers, underscores refer to any combination, not all three must be included) cannot start with a number
Password:
Must be 6-20 digits of letters, numbers, underscores (here letters, numbers, underscores refer to any combination, there is no need to include all three categories)
Package cn.zyq.Aug05;import java.util.Scanner;public class Demo1 {public static void main (String [] args) {Scanner sc = new Scanner (System.in); System.out.println ("Please fill in the user name:"); String name = sc.next (); / * * verify the user name * while loop control until the input is legal * / while (! checkName (name)) {System.out.println ("invalid user name, please re-enter:") Name=sc.next ();} / * verify password * / System.out.println ("Please fill in password:"); String pwd=sc.next (); while (! checkPwd (pwd)) {System.out.println ("invalid password, please re-enter:"); pwd=sc.next ();} System.out.println ("registered successfully!") ;} / * * user name authentication * @ param name * @ return * / public static boolean checkName (String name) {String regExp = "^ [^ 0-9] [\\ w _] {5pm 9} $"; if (name.matches (regExp)) {return true;} else {return false }} / * password authentication * @ param pwd * @ return * / public static boolean checkPwd (String pwd) {String regExp = "^ [\\ w _] {6 return true; 20} $"; if (pwd.matches (regExp)) {return true;} return false }} Thank you for reading this article carefully. I hope the article "how to use regular expressions to verify user names and passwords with Java" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you to learn!
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: 297
*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.