I have a form where I need to validate the textboxes like Firstname, Middlename, Lastname, emailId, date, mobilenumber. The validation should happen when a user starts typing in the textbox. errorprovider should show message under textbox if a user enters numbers in place of text and text in place of numbers. I got to know about implicit validation and explicit validation but I feel better to use implicit validation only because its on time error provider when user looses focus on text box or if he shifts to another textbox. I've posed this kind of question with a explicit validation code but no one responded me. So Im making it simple to get help. Do not think I havent done enough research before posting this question.
You should take a look to the TextChanged Event in of your textbox.
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.textchanged.aspx
This event is raised if the Text property is changed by either a programmatic modification or user interaction.
I would do something like this
private void TextBoxExample_TextChanged(object sender, EventArgs e)
{
TextBox box = sender as TextBox;
if (box.Text.Contains("Example"))
{
LabelError.Text = "Error";
}
else
{
LabelError.Text = string.Empty;
}
}
Hope it helps :)