You can use String#matches() to check if a name begins with any of the special characters on your blacklist:
if (name.matches("(?:!|@|#|\\$|%|\\^|&|\\*|\\(|\\)|_|\\+|\\?|>|<).*")) {
System.out.println("Enter valid name");
}
Another way:
String specialChars = "!@#$%^&*()_+?><";
if (specialChars.indexOf(name.charAt(0)) != -1) {
System.out.println("Enter valid name");
}
solved If the first name, last name and the nick name starts with the special chars [closed]