Possible Duplicate:
How do I create a regular expression to accept not more than 10 digits?
I want a regular expression which will allow up to 10 digits in a user control having a text box. (ASP.net 3.5).
match(/(\d{5})/g);
A repeat is an expression that is repeated an arbitrary number of times. An expression followed by '*' can be repeated any number of times, including zero. An expression followed by '+' can be repeated any number of times, but at least once.
'?' matches/verifies the zero or single occurrence of the group preceding it. Check Mobile number example. Same goes with '*' . It will check zero or more occurrences of group preceding it.
^[0-9]{1,10}$
or ^\d{0,10}$
Add regular expression validator with your textbox:
<asp:TextBox ID="tb" runat="server" MaxLength="10" />
<asp:RegularExpressionValidator ID="rvDigits" runat="server"
ControlToValidate="tb" Text="*" Display="Dynamic"
ValidationExpression="^\d{0,10}$" />
A better approach will be to use jQuery and jquery.numeric plugin!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With