So what I'm trying to do is take String input and validation to the following correspondences:
1. Take no Digits "1234567890"
2. Take no Symbols/Special Characters "!@£$%^&*()"
OUTPUT FROM TESTING FOLLOWING CODE:
Please enter your name:
John Smith2323
Found a special character
Name: J Smith2323
So... The program has detected a special character, or a digit. So it printed "Found Special Character..."... So my code is half way there...
What I need to do, is detect the special character, and if this is detected then it should ask for the input again. It will keep asking for the input until the input has only a letter values and a whitespace.
I might need a loop in here somewhere, but I am not sure where I should put it... or how to structure it... maybe some boolean values as well?
System.out.println("Please enter your name: "); n = kbd.nextLine(); char[] chars = n.toCharArray(); boolean sChar = false; for(char c : chars) { if(!Character.isLetter(c) && (!Character.isWhitespace(c))) { sChar = true; } } if(sChar == true) { System.out.println("Found a special character"); }