TEXTBOX VALIDATION FOR INDIAN PAN CARD NUMBER USING TEXTBOX VALIDATINGEVENT
In this post we will see the sample code for validating Textbox in C#.Net winforms 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
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 […]