I have a method I'm using to validate user-inputted values in a program. Whenever the user inputs a string into a JOptionPane, I call this method and pass in the inputted string, plus the maximum and minimum values I need their input to be between. First I check if the input is an integer by trying to parse the input string and catching exceptions, then I check if the integer is between the min and max. My problem is that if the user inputs another incorrect non-integer value after being prompted, I don't know how to check if the new value is correct or not. Here is the method, can anybody help?

```
int checkInput(String input, int min, int max) {
        Boolean isInteger = false;
        Boolean inputAccepted = false;
        int userInput = 0; //will be set later
        while (!isInteger) {
            try
            {
                userInput = Integer.parseInt(input);
            }
            catch (NumberFormatException e)
            {
                userInput = Integer.parseInt(JOptionPane.showInputDialog("Please enter only integers between " + min + " and "+ max + "."));
                isInteger = true; //the problem here is that it assumes the user inputted a correct value after being prompted... what if they enter another incorrect value?
            }
        }
        while (!inputAccepted) {
        if (userInput < min || userInput > max) 
        {
                userInput = Integer.parseInt(JOptionPane.showInputDialog("Please enter only integers between " + min + " and "+ max + "."));
        }
        else 
        {
            inputAccepted = true;
        }
        }
        return userInput;
    }

```