Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Validate numeric textbox using int.tryparse visual C#.NET

3.67/5 (3 votes)
12 Sep 2011CPOL 15.2K  
You could do the same thing with a regular expression:if (Regex.Replace(textBox1.Text, @D, ) == textBox1.Text){textBox2.Text = (tryparse method succeed);} else { textBox2.Text=(value entered is not numeric); }
You could do the same thing with a regular expression:

C#
if (Regex.Replace(textBox1.Text, @"\D", "") == textBox1.Text)
{
textBox2.Text = ("tryparse method succeed");
} else { textBox2.Text=("value entered is not numeric"); }

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)