Java uses regular expressions to write simple account password registration judgment

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.