0

I have user input

private Scanner inn = new Scanner(System.in);
String input = inn.nextLine().toLowerCase();

and i need to throw IllegalCharacterException(own exception, created this class already) for not desired input (all numerals and symbols and maybe even other languages)I need only english letters. How can i do that? Thank you.

1 Answers1

0

You can use String.matches(String regex) with regular expressions. E.g.

private Scanner inn = new Scanner(System.in);
String input = inn.nextLine().toLowerCase();
if(input.matches("[a-z]*")) {
  // Do some stuff
}

The Regular expression [a-z]* matches any character from a to z (lowercase), without any numbers, symbols or spaces.

malliaridis
  • 389
  • 1
  • 12