Home > Back-end >  Java problem solving
Java problem solving

Time:10-27

Wanted to make a string used to judge the user input is in compliance with the requirements of the program, the requirements are: 1. The first one must be uppercase letters, 2. Must contain 5 Numbers, 3. The length of the string between 6 and 16 but make half a day to finally determine the length of the regular expression is wrong, what all don't conform to the requirements, specific look at the picture, the validation of capital letters and five digital expression tested no problem, {5, 15} is behind the question, for a great god teach

CodePudding user response:

String length is between 6 and 16 wrote
^. 16th {6} $

CodePudding user response:

refer to the original poster m0_51133914 response:
wanted to make a string used to judge the user input is in compliance with the requirements of the program, the requirement is: 1. The first one must be uppercase letters, 2. Must contain 5 Numbers, 3. The length of the string between 6 and 16 but make half a day to finally determine the length of the regular expression is wrong, what all don't conform to the requirements, specific look at the picture, the validation of capital letters and five digital expression tested no problem, {5, 15} is behind the question, for a great god teach


String BDS="^ \ \ w * [a-z] [0-9] {5} + ${5, 15}";

CodePudding user response:

refer to the second floor qq_39936465 response:
Quote: refer to the original poster m0_51133914 response:
wanted to make a string used to judge the user input is in compliance with the requirements of the program, the requirements are: 1. The first must be uppercase letters, 2. Must contain 5 Numbers, 3. The length of the string between 6 and 16 but make a half-day finally determine the length of the regular expression is wrong, what all don't conform to the requirements, specific look at the picture, in front of the validation of capital letters and five digital expression tested no problem, {5, 15} is behind the question, for a great god teach


String BDS="^ \ \ w * [a-z] [0-9] {5} + ${5, 15}";
try this, you still won't do, input validation to success is more than 16 characters

CodePudding user response:

reference m0_51133914 reply: 3/f
tried this, you still won't do, input validation to success is more than 16 characters


I feel the need to double the regular

 
Scanner in=new Scanner(System.in);
String BDS="^ \ \ w * [a-z] [0-9] {5} \ \ w *";
String BDT={5, 15} \ \ "" w".
While (true) {
String c=in nextLine ();
If (c. atches (BDS) & amp; & C. atches (BDT)) {
System. The out. Println (" proves successful, ");
} else {
System. The out. Println (" authentication failed ");
}
}

CodePudding user response:

Ha ha, in fact, this is quite simple, would, of course, if it's really simple

 
String regx="^ [a-z] ((?=(. *) \ \ d {5}) ([a zA - Z \ \ d]) {5, 15} $");
String [] testData={
https://bbs.csdn.net/topics/"1234567890",//digital
"AbcdEFGhij",//the whole letter
"ABcd12",//digital enough 5
"12345 a",//the capital letter
"A12345",//OK, full six
"AB1cd2EF3gh4IJ5",//OK 16 bits, at least five Numbers, capital letter
"A123456789012345",//OK with 16 bits, at least five Numbers, capital letter
"Aabcdefg12345abc",//OK with 16 bits, at least five Numbers, capital letter
"AB1cd2EF3gh4IJ5k6"//17
};
For (String s: testData) {
System. The out. Printf (" % s: % s \ n ", s, s.m atches (regx));
}

CodePudding user response:

Qq_39936465
reference 4 floor response:
Quote: refer to the third floor m0_51133914 response:
try this, you still won't do, input validation to success is more than 16 characters


I feel the need to double the regular

 
Scanner in=new Scanner(System.in);
String BDS="^ \ \ w * [a-z] [0-9] {5} \ \ w *";
String BDT={5, 15} \ \ "" w".
While (true) {
String c=in nextLine ();
If (c. atches (BDS) & amp; & C. atches (BDT)) {
System. The out. Println (" proves successful, ");
} else {
System. The out. Println (" authentication failed ");
}
}


Double was a good idea, a, feasible, but you need to change the String under BDT=5 dec} {\ \ "" w". Otherwise matching 16 length also failed
  • Related