Hi all c# lovers,
I want to check the input string ( to a textbox) is a numeric value or not. what is the easiest method to do this? can someone give me a sample code for that... I hope .net has some methods to validate these formats.
thank you....
Validate Integers.....
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Jan MontanoRank #1,295 · 1.3K reputationPosted Jun 20, 2007, 7:34 PM EDT
int i;
if (Int32.TryParse("123", out i))
{
// numeric
}
else
{
// not numeric
}
AlanRank #669 · 3.6K reputationPosted Jun 21, 2007, 12:52 AM EDT
Thought I'd just add that the TryParse() methods are only available in .NET 2.0 or later.
If you're using .NET 1.0 or 1.1, you can replicate it with:
int i;
bool isValid = true;
try
{
i = Int32.Parse(textBox1.Text);
}
catch
{
isValid = false;
i = 0;
}