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.
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();
     }
 }

 

1 thought on “TEXTBOX VALIDATION FOR INDIAN PAN CARD NUMBER USING TEXTBOX VALIDATINGEVENT”

Leave a Reply

Your email address will not be published. Required fields are marked *