Generally I used to validate textboxes that has to take digits as inputs we can specify range too.
The Regular expression is as follows
@"^\d{0,9}$"
This Regular expression is tested and I would really welcome any corrections and suggestions.
The usage is as follows.
private void button1_Click(object sender, EventArgs e)
{
if (Regex.IsMatch(textBox1.Text, @"^\d{0,9}$"))
{
MessageBox.Show("ok");
}
else
{
MessageBox.Show("is not matched");
}
}
This is code snippet for validating textbox value for numbers between range 0 to 9.
ShantanuPosted Jan 15, 2011, 10:30 PM
A good online resource on Regular Expressions is : http://www.regular-expressions.info/tutorial.html This tutorial covers all concepts in Reg Ex.
ShantanuPosted Jan 15, 2011, 10:22 PM
Hi Rakesh, Your Regex can be used for numbers with upto 10 digits. However, if you want a more generic one to accept any number of digits, you can use this : 0 or more digits : ^\d*$ or one or more digits: ^\d+$ Also, for testing your .Net Regular Expressions you can use online testers like : http://derekslager.com/blog/posts/2007/09/a-better-dotnet-regular-expression-tester.ashx