d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Java Help Data-type Validation
Add Reply New Topic New Poll
Member
Posts: 4,506
Joined: Oct 9 2005
Gold: 102.54
Feb 6 2022 08:46am
In my very basic program I am asking user to input a string (ingredient)

Scanner scnr = new Scanner(System.in);

System.out.println("Please enter the name of the ingredient: ");

nameOfIngredient = scnr.next();


How do I make sure that the user is not inputting something silly like 123456.


I just cannot figure out how to filter the users input with WORDS. I know the string will accept 123456 but I want to be able to have my simple program be like "Hey you did not enter in a name of ingredient" if they enter in numbers.

Hope that makes sense lol.
Ty to anyone who reads this silly post, I'm so confused tho!

This post was edited by GoldRaker1337 on Feb 6 2022 08:47am
Member
Posts: 4,506
Joined: Oct 9 2005
Gold: 102.54
Feb 6 2022 09:23am
I figured out a workaround! Please disregard =) Have a great day!
Member
Posts: 30,945
Joined: Apr 13 2008
Gold: 11,996.69
Mar 25 2022 06:10am
regex would be great and easily extendable
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll