I want validation module to work when the user leaves the textbox or the textbox is out of focus. i.e. when the user input in one textbox and then focus on other textbox for input instantly error message should popup if the previous input is not valid.
here error message should popup instantly for txtName if it is invalid when txtName is out of focus.
I've develop a module for validation but it works when the form is complete,i.e. only at the save time.
#region "Input Validations"
private bool IsClientValid()
{
if (txtUsername.Text == string.Empty || txtUsername.Text == null)
{
MessageBox.Show("User Name is required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
if (txtUsername.Text.Length > 200)
{
MessageBox.Show("User Name cannot be more than 200 characters", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
if (txtPhone.Text.Length > 20)
{
MessageBox.Show("Phone Number cannot be more than 20 characters", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
return true;
}
#endregion