I am a beginner programmer (first post here!) and I cannot figure out how to create an error message with a "do while" loop. If given input that's not in the alphabet it is supposed to display the error message until given an input with only letters and then move on the to rest of the program. My code seems to loop forever even if given correct input. Any suggestions are greatly appreciated! :)
do {
input = JOptionPane.showInputDialog("What is your name?");
if (input.contains("[a-zA-Z]"))
name = input;
else
System.out.println("Please enter a valid name containing: ‘a-z’ or ‘A-Z’ lower or upper case");
} while (!input.contains("[a-zA-Z]"));