Java write simple account password Registration Judge rookie just learned expression practiced hand code.
1/* When registering is usually to verify the user name and password is legitimate, using the learned knowledge to complete the following operations: 2 3 username length is greater than or equal to 6 bits, must contain the number and the English letter 4 5 password length is equal to 8 bits, must contain a special match _ or $, the English alphabet and the number 6 7 to Two conditions at the same time to establish a registration to succeed. 8 9 * */importJava.util.Scanner; ImportJava.util.regex.Matcher; ImportJava.util.regex.Pattern; public classJob 3 {public static voidMain (string[] args) {Scanner sr = newScanner (system.in); while (true) {System.out.println ("Please enter your username:")); The String userName = Sr.next ();//user name entered when user registration is accepted. P = Pattern.compile ("[A-za-z][0-9]"); Notoginseng Matcher m =P.matcher (UserName); if (Username.length () < 6) {System.out.println ("User name length needs to be greater than 6"); Continue; M.find} else if ((){System.out.println ("user name entered correctly.")); Break; The Else{System.out.println ("does not contain numbers or letters")); Continue; 56 57} 58 59} (True ) {System.out.println ("Please enter password:" ); The Userpass String = sr.next (), the P1 = Pattern.compile ("[a-za-z][0-9]" ), and the pattern P2 = Pattern.compile ("[$]" ); p3 = Pattern.compile ("[_]" ); Matcher m1 = P1.matche R (Userpass); Matcher m2 = p2.matcher (userpass), the Matcher m3 = p3.matcher (userpass); Gth () < 8 ) {System.out.println ("password needs to be greater than 8 bits" ); continue ;} else if (M1.find () &&A mp (M2.find () | | M3.find ())) {94 SYSTEM.OUT.PRINTLN ("registered successfully" ), "98", "", "101 System.out.println" ("Password needs to contain symbols _ or $ and must not be missing the letters and Numbers ""); 102 103 Continue 104}106 107 }108 109 }110 span>
Java uses regular expressions to write simple account password registration judgment