Java uses regular expressions to verify the registration page. java Regular Expressions

Source: Internet
Author: User

Java uses regular expressions to verify the registration page. java Regular Expressions

This article introduces the code for java to verify the registration page using regular expressions. The Code is as follows:

Package regex; import java. util. imports; import java. util. regex. matcher; import java. util. regex. pattern; public class registered {public static void main (String [] args) {// registered user login SC = new Login (System. in); System. out. println ("Enter the User name:"); String uname = SC. next (); System. out. println ("enter the password:"); String passwd = SC. next (); System. out. println ("enter the password for confirmation:"); String repasswd = SC. next ();/* String uname = "wangheng"; Stri Ng passwd = "222assAS123"; String repasswd = "432Pass123"; */boolean B = uname. matches ("\ w {3, 10}"); // method 1 if (B = true) {Pattern p0 = Pattern. compile (". {6, 12} "); // length: 6 to 12 Pattern p1 = Pattern. compile (". * [A-Z] + "); // Pattern p2 = Pattern. compile (". * [a-z] + "); Pattern p3 = Pattern. compile (". * \ d + "); Matcher m0 = p0.matcher (passwd); Matcher m1 = p1.matcher (passwd); Matcher m2 = p2.matcher (passwd); Matcher m3 = p3.matcher (passwd ); if (m0. LookingAt () = true & m1.lookingAt () = true & m2.lookingAt () = true & m3.lookingAt () = true) {boolean b2 = passwd. matches (repasswd); if (b2) {System. out. println ("registration successful! ");} Else {System. out. println (" confirm that the password is different from the password! ") ;}} Else {System. out. println (" Incorrect password! ") ;}} Else {System. out. println (" incorrect user name! ");} // Method 2 Pattern p1 = Pattern. compile ("[A-Z] +"); Pattern p2 = Pattern. compile ("[a-z] +"); Pattern p3 = Pattern. compile ("\ d +"); Matcher m1 = p1.matcher (passwd); Matcher m2 = p2.matcher (passwd); Matcher m3 = p3.matcher (passwd); if (uname. matches ("\ w {3, 10}") & passwd. matches (". {6, 12} ") & m1.find () & m2.find () & m3.find () {System. out. println ("registration successful! ");} Else {System. out. println (" registration failed! ");}}}

The above section describes how to use regular expressions to verify the registration page in Java. I hope this will be helpful to you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.