So, I've been working on this problem for a few hours now, and I've scanned the internet extensively. I cannot figure out why this is not working for the life of me. When I enter numbers, it prompts me to re-enter, which is correct. However, when you type in a string ("FJASFJ") it still asks me to re-enter the information, I've been print.ln to see where the program is messing up and I'm still stuck :/
import javax.swing.JOptionPane;
public class functions {
private static boolean x;
private static String name;
private static String fur;
private static Number weight;
public static void nameExceptionFunc(String startName){
if(!(startName instanceof String)){
name=startName;
}else{
x=false;
while(x==false){
System.out.println("Sorry, but that is not an acceptable string.");
startName=JOptionPane.showInputDialog("Re-enter an acceptable value for your cat's name: ");
if(!(startName instanceof String)){
System.out.println("o");
name=startName;
break;
}else{
System.out.println("i");
continue;
}
}
}
}
instanceof. It is used to check the class type of the variable. You may try regular expression for your need. e.g.startName.matches("^[A-Za-z]*$")