private void txt_nic_TextChanged(object sender, EventArgs e) { string str = txt_nic.Text; formValidator3.Clear(); if (!(str.Length == 0)) { if ((str.Count(char.IsDigit) == 9) && // only 9 digits (str.EndsWith("X", StringComparison.OrdinalIgnoreCase) || str.EndsWith("V", StringComparison.OrdinalIgnoreCase)) && //a letter at the end 'x' or 'v' (str[2] != '4' && str[2] != '9')) //3rd digit can not be equal to 4 or 9 { FormValidator.Clear(); FormValidator2.Clear(); } else { FormValidator2.Clear(); FormValidator.SetError(txt_nic, "please check your NIC Number"); } } else { FormValidator2.SetError(txt_nic, "Please enter your nic number"); } }
private void txt_mobile_KeyPress(object sender, KeyPressEventArgs e) { if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.')) { e.Handled = true; FormValidator2.SetError(txt_mobile, "Please check your contact Number"); } else { this.FormValidator2.Clear(); } }
private void txt_faxNum_KeyPress(object sender, KeyPressEventArgs e) { if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.')) { e.Handled = true; FormValidator2.SetError(txt_faxNum, "please check your fax number again"); } else { this.FormValidator2.Clear(); } }
private void txt_companuName_KeyPress(object sender, KeyPressEventArgs e) { if (Char.IsControl(e.KeyChar) != true && Char.IsNumber(e.KeyChar) == true) { if (!(e.Handled == true)) { FormValidator2.SetError(txt_cmpnyName, "Accepting only Charactors"); e.Handled = true; } } else if (Char.IsControl(e.KeyChar) == true && Char.IsNumber(e.KeyChar) == false) { FormValidator2.Clear(); } }