Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate number? 1

Status
Not open for further replies.

mtbcoach

Programmer
Feb 11, 2001
9
CA
Hi,

How can i validate a string that a receive, to vérifie if this is a number or a string.

Thank you for your time and help!
 
Depends on what kind of number you are expecting. If you are expecting an integer, try to parse it as an int. If it won't parse, it's not a number. You can do the same thing if you are expecting a FP number using Double or Float classes.

int myNum;
try {
myNum = Integer.parseInt(theString);
} catch (NumberFormatException e) {
// It's NOT a number
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top