I am trying to validate input from a textfield so that it only contains characters from a-z. I am using the following method to validate if the input is an int:
//VALIDATE IF INPUT IS NUMERIC.
public static boolean isInt(JFXTextField txtUserInput, String userInput) {
try {
int intValidation = Integer.parseInt(userInput);
txtUserInput.setStyle("-fx-border-color: ; -fx-border-width: 0px ;");
return true;
} catch(NumberFormatException exception) {
showErrorMsg("Invalid Input:", "Please enter a numeric-only value");
txtUserInput.setStyle("-fx-border-color: RED; -fx-border-width: 1px ;");
return false;
}
}
How can I achieve this using a String? I know there is a different way of doing this using an if statement but I was wondering if I can catch an exception like in the example above.
Thanks