There are a couple approaches.
1) You can look at the string and see if it looks like a number. Regular expressions could match digits and decimal points and signs and all those things. If you're pre JDK 1.4 and don't have regular expressions, you can inspect each character. You'd pretty much have to duplicate all the syntax rules of
Java numbers to handle all numeric types.
2) Use one of the numeric types to parse the String, like Integer.parseInt(String). If you feed it non numeric data, or data out of range or otherwise unsuitable to the type, you'll get an exception to let you know. You can do this in a few lines without knowing the syntax and ranges and so on, because the JDK will do all the checking for you.
With either approach, consider creating a utility class to house the logic. "Utility" here is an unofficial OO term for classes with all static methods. You'll be able to use it like this for years to come: