Sunday, March 25, 2012

Validate Indian PAN number using Regular Expression

PAN structure is as follows: AAAAA9999A: 

First five characters are letters, next 4 numerals, last character letter

The rule for the fourth character as below:
 
The fourth character of the PAN must be one of the following, depending on the type of assesse:
C — Company
P — Person
H — HUF(Hindu Undivided Family)
F — Firm
A — Association of Persons (AOP)
T — AOP (Trust)
B — Body of Individuals (BOI)
L — Local Authority
J — Artificial Juridical Person
G — Government

Regular Expression for PAN is as below:

^[\w]{3}(p|P|c|C|h|H|f|F|a|A|t|T|b|B|l|L|j|J|g|G)[\w][\d]{4}[\w]$

Use it in .Net as below:
       <asp:RegularExpressionValidator ID="revPAN" 
ControlToValidate="txtPAN" runat="server" ErrorMessage="Invalid PAN"
ValidationExpression="[\w]{3}(p|P|c|C|h|H|f|F|a|A|t|T|b|B|l|L|j|J|g|G)[\w][\d]{4}[\w]"></asp:RegularExpressionValidator>

ITWORLD
If you have any question then you put your question as comments.

Put your suggestions as comments