In this article I will explain with an example, how to implement Indian PAN Card Number validation using RegularExpressionValidator in ASP.Net.
The PAN Card Number entered in the TextBox will be validated on Button click using Regular Expression (Regex) and RegularExpressionValidator in ASP.Net.
HTML Markup
The following HTML Markup consists of a TextBox, a Button and an ASP.Net RegularExpressionValidator.
The RegularExpressionValidator has been assigned the Regular Expression for validating Indian PAN Card Number in the ValidationExpression property.
PAN Card:
<asp:TextBox ID="txtPANCard" runat="server" CssClass="PAN" />
<asp:RegularExpressionValidator ID="rgxPANCard" runat="server" ValidationExpression="([A-Z]){5}([0-9]){4}([A-Z]){1}$" ControlToValidate="txtPANCard" ErrorMessage="Invalid PAN Number" CssClass = "error"></asp:RegularExpressionValidator>
<hr />
<asp:Button ID="btnSubmit" Text="Submit" runat="server" />
CSS Class
The following CSS classes are used.
1. PAN – It will force the letters to be UPPER case.
2. error – It will apply RED color to the error message.
<style type="text/css">
.PAN
{
text-transform: uppercase;
}
.error
{
color: Red;
}
</style>
Screenshot
Invalid PAN Card Number
Valid PAN Card Number
Demo
Downloads