
hi i need java expression which allows all characters with minimum 2 characters and maximum 20 characters in answers field after selecting security questions

import java.util.*;
import java.util.regex.*;
class RegularExpression {
public static boolean validateString(String st) {
return st.matches("^[a-zA-Z]{2,20}$");
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter String: ");
String str = input.nextLine();
while (validateString(str) != true) {
System.out.print("Invalid String!");
System.out.println();
System.out.print("Enter String: ");
str = input.nextLine();
}
}
}

import java.util.*;
import java.util.regex.*;
class RegularExpression {
public static boolean validateString(String st) {
return st.matches("^[a-zA-Z]{2,20}$");
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter String: ");
String str = input.nextLine();
while (validateString(str) != true) {
System.out.print("Invalid String!");
System.out.println();
System.out.print("Enter String: ");
str = input.nextLine();
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.