In this post we will the sample code for validating Textbox in windows c# for indian pan card number using Regular Expression in TextBox Validating Event . In the below code we are using a errorprovider to show if the entered pan number is in wrong / invalid format.
private void txt_PanNo_Validating(object sender, CancelEventArgs e) { System.Text.RegularExpressions.Regex rPan = new System.Text.RegularExpressions.Regex(@"^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}?$"); if (txt_PanNo.Text.Length > 0) { if (!rPan.IsMatch(txt_PanNo.Text)) { errorProvider2.SetError(txt_PanNo, "Invalid PAN Card Number"); txt_PanNo.SelectAll(); e.Cancel = true; } else { errorProvider2.Clear(); } } else { errorProvider2.Clear(); } }
[...] Visit Post : TEXTBOX VALIDATION FOR INDIAN PAN CARD NUMBER USING TEXTBOX VALIDATING EVENT [...]
ReplyDelete