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!