How should I validate textbox for only accepting numbers, only alphabets other important validations that could be needed. Using properties window of visual studio. Or any other best way.
private void txt5ValGood_TextChanged(object sender, EventArgs e)
{
if (System.Text.RegularExpressions.Regex.IsMatch(txt5ValGood.Text, "[^0-9]+"))
{
txt5ValGood.Text = System.Text.RegularExpressions.Regex.Match(txt5ValGood.Text, "[0-9]+").ToString();
}
}
This is a duplicate, but I'll take a quick second to answer it.
What I've done in the past is let the user enter text in a text box, and wait for an event to require validating it - usually them pressing a button or some event that indicates they want to do something with what they just entered.
In the code for that event, what you can do is iterate through the string, and check each character for whatever requirement you desire. For instance, for a digit check you could do:
It would be helpful to take a look at the MSDN page for char methods to see how these checks are used.