In this article I will explain with an example, how to implement Aadhaar Number validation using RegularExpressionValidator in ASP.Net.
The Aadhaar Number entered in the TextBox will be validated using Regular Expression (Regex) and ASP.Net RegularExpressionValidator.
HTML Markup
The following HTML Markup consists of a TextBox, an ASP.Net RegularExpressionValidator and a Button control.
The RegularExpressionValidator has been set with a Regular Expression for validating Aadhaar Number in the ValidationExpression property.
The following Aadhaar Number formats will be termed as valid.
1. 12 digits without space. Ex: 569832598526
2. White space after every 4th digit. Ex: 5698 3259 8526
3. Hyphen (-) after every 4th digit. Ex: 5698-3259-8526
Aadhaar Number:
<asp:TextBox ID="txtAadhaar" runat="server" />
<asp:RegularExpressionValidator ID="rgxAadhaar" runat="server" ControlToValidate="txtAadhaar"
    ErrorMessage="Invalid Aadhaar Number" ForeColor="Red"></asp:RegularExpressionValidator>
<asp:Button ID="btnSubmit" Text="Submit" runat="server" />
Aadhaar Number validation using RegularExpressionValidator in ASP.Net