I would like to know how to either prevent the entering of characters in an input statement or test a string for all numeric input then converting to a numeric data type. Is there a simple way to go about this?
One way would be to break the String into a char array, create a Character object for each character in the array and use the isDigit() method to test if it is a number or not. What you want to do from there depends on whether or not you want to pull the number out and have a new String, or leave it in there. Jason
you could simply use the charAt() method to disect the string char by char checking unicode values and such to make sure only numbers are entered.
Chicken Farmer ()
Joined: May 08, 2001
Ah, you want nothing but numbers, misread the question. Same thing would go depending on what you wanted to do. If you want to drop the characters that aren't numbers, you'd still have to break it out into an array to copy, or create a StringBuffer and remove them that way based on the index you get back from charAt(). If you just wanted to through an error up or something, Matt's way would be simple. Jason