How do I validate a textBox ?

If I attach a validating method to a textbox like the example code below, when is it called
After losing focus from the textbox It doesn't seem to work.
In the Compact Framework there is no ErrorProvider control what is the correct way to display validation errors Certainly not a MessageBox like I did...

Thanks

private void textBoxNumericCode_Validating(object sender, CancelEventArgs e)
{
if (string.IsNullOrEmpty(txtbNumericCode.Text))
{
MessageBox.Show("Numeric Code is mandatory!");

}
else if (!Regex.IsMatch(textBoxNumericCode.Text, @"[0-9]+"))
{
MessageBox.Show("Please input a numeric value!");
}
}




Answer this question

How do I validate a textBox ?

  • Ultrawhack

    I don't know if this helps:
    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=323570&SiteID=1

  • How do I validate a textBox ?