How To Allow Only Numbers In TextBox Control?

 Posted by Vishalneeraj-24503 on 4/26/2015 | Category: Visual Studio Interview questions | Views: 578 | Points: 40
Answer:

We will use Regex.IsMatch method to alow only numbers.
For working with Regex classes,we have to import
System.RegularExpression Namespace.
Using System.RegularExpression.

if (!Regex.IsMatch(txtNumbersOnly.Text,
@"(^([0-9]*|\d*\d{1}?\d*)$)"))
{
MessageBox.Show("Not a Number");
}


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response