I want a regular expression that accepts as input characters (A..Z or a..z) and does not accept numbers and special characters. I wrote this method and these patterns but it doesn't work:
public static Pattern patternString = Pattern.compile("\\D*");
public static Pattern special = Pattern.compile("[!@#$%&*,.()_+=|<>?{}\\[\\]~-]");
public static boolean checkString(String input) {
boolean bool_string = patternString.matcher(input).matches();
boolean bool_special = !special.matcher(input).matches();
return (bool_string && bool_special);
}
checkString
should return true if the input is: hello, table, Fire, BlaKc, etc.
checkString
should return false if the input is: 10, tabl_e, +, hel/lo, etc.
How can I do that? Thank you