Regular Expression for 6 digits number including 0

Jak
Jak
908 Points
132 Posts

Regular Expression for 6 digits number including 0

Views: 9599
Total Answered: 1
Total Marked As Answer: 1
Posted On: 26-Dec-2014 09:19

Share:   fb twitter linkedin
Answers
Rahul Maurya
Rahul M...
4916 Points
27 Posts
         

If you want a Regular Expression that can accept exactly 6 digits, it would be the following :

^\d{6}$

An implementation might look something like this :

<!-- Your Textbox -->
<asp:TextBox ID="YourTextBox" runat="server"></asp:TextBox>

<!-- Your Regular Expression Validator -->
<asp:RegularExpressionValidator ID="YourRegularExpressionValidator" runat="server" 
                                ControlToValidate="YourTextBox" 
                                ErrorMessage="Your TextBox must have exactly 6 digits."  
                                ValidationExpression="^\d{6}$">
</asp:RegularExpressionValidator>

<!-- This will trigger your validation -->
<asp:Button ID="ValidateButton" runat="server" Text="Validate" />
Posted On: 26-Dec-2014 09:22
 Log In to Chat