PAN Card Validation Using ASP.Net

In many forum posts I have read one common question. That is, how to validate a Permanent Account Number (PAN) card. But no one provides the proper solution so by considering that requirement I have decided to write this article. So let us learn about this requirement step-by-step.
 
PAN Cards
 
A PAN is an identifier of Indian Tax Payers and is a 10 alphanumeric unique number.
A PAN card has the following characteristics.
  1. Is a combination of letters and numbers having a length of 10
  2. All letters are in upper case.
  3. A PAN card number always starts and ends with letters.
  4. Does not contain special characters.
  5. The PAN card number starts with five letters then has four digits and the last one is a letter.
  6. Each holder is uniquely defined as below:
A — Association of Persons (AOP)
B — Body of Individuals (BOI)
C — Company
F — Firm
G — Government
H — HUF (Hindu Undivided Family)
L — Local Authority
J — Artificial Judicial Person
P — Individual
T — AOP (Trust)
Suppose the PAN card for a person starts with an A, for example:
AAAPL1234C 
Step 1:  Now from the preceding PAN card structure, let us create the regular expression for it as:
  1. [A-Z]{5}\d{4}[A-Z]{1} 
 Now let us create the web application to use the above regular expression to validate the PAN card.
 
Step 2: Create the web application as in the following.
  1. "Start" - "All Programs" - "Microsoft Visual Studio 2010".
  2. "File" - "New WebSite" - "C#" - "Empty WebSite" (to avoid adding a master page).
  3. Provide the web site a name such as "PANcardValidation" or another as you wish and specify the location.
  4. Then right-click on Solution Explorer and select "Add New Item" then add a Web Form.
  5. Drag and drop one TextBox onto the <form> section of the Default.aspx page.
  6. Now the Default.aspx page source code will look such as follows.
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>  
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
    <title></title>  
</head>  
<body style="background-color: #000080">  
    <form id="form1" runat="server">  
    <h5 style="color: #FF3300; font-size: large;">  
        PAN Card Validation</h5>  
    <table style="margin-top: 20px; color: White">  
        <tr>  
            <td>  
                Enter PAN Card  
            </td>  
            <td>  
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>  
            </td>  
            <td>  
                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox1"  
                    Display="Dynamic" ForeColor="Red" ErrorMessage="InValid PAN Card" ValidationExpression="[A-Z]{5}\d{4}[A-Z]{1}"></asp:RegularExpressionValidator>  
            </td>  
        </tr>  
    </table>  
    </form>  
</body>  
</html> 
Step 3: Now run the application, the UI will be look as follows:
 
 Now enter an invalid PAN card number with a small letter; it wil show the following error message:
 
In the preceding it shows an error because all the letters are in small case and not in the proper structure.
Now enter following input and again it shows the error message as:
 
In the preceding image, it shows the error message even 10 characters in length and all capital letters because the PAN card structure does not match.
Now enter the following input with one letter missing, again it shows the following error:
 
 
In the preceding image, it shows the error message even all capital letters because one letter is missing.
 
Now enter a proper PAN number, it will not show an error as:
 
In the preceding example, it does not show an error message because the preceding PAN number is correct as per the structure.
 
Note
  • I have used a dummy PAN card, you can use any PAN number
Summary
For all the preceding  examples, we have learned how to validate the PAN card. I hope this article is useful for all readers. If you have a suggestion then please contact me.

Post a Comment

www.CodeNirvana.in

Protected by Copyscape
Copyright © Compilemode