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....
Loading
AlanPosted Jun 21, 2007, 4:52 AM
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;
}
Jan MontanoPosted Jun 20, 2007, 11:34 PM
int i;
if (Int32.TryParse("123", out i))
{
// numeric
}
else
{
// not numeric
}