I am trying to create a code that would reject an answer that only contains whitespace/spaces. So far I already made a code to reject empty inputs but once the user inputs spaces, the program accepts it.
How do I prevent this? Thank you!
do {
while(true) {
System.out.print("Dog's name: ");
String dogName = null;
dogName = scan.nextLine().toLowerCase();
String n = dogName.replaceAll("\\s", "");
if(dogName.isEmpty()) {
System.out.println("Error: Name can't be empty.");
continue;
}