I am trying to limit the number of text into a Textbox field. The requirement is to fix the minimum length as 7 and maximum length as 15.
I have tried to use the asp:RegularExpressionValidator to limit the number of text into the textbox.
Here is my code:
<asp:RegularExpressionValidator ID="revphone" runat="server"
Font-Size="16px"
ValidationExpression="^[0-9]{7,15}$"
ControlToValidate="txtphonenumber"
ErrorMessage="*"
ValidationGroup="reg"
Display="Dynamic"
ForeColor="Red">
</asp:RegularExpressionValidator>Phone Number
<asp:TextBox ID="txtphonenumber" runat="server"
placeholder="Phone Number"
Width="305px"
onblur="BtnRegisterClick()"
MaxLength="7">
</asp:TextBox>
I am able to get the minimum number but not getting the maximum number. It is limiting to type 7 digits only.
Here is Your Solution:-
<asp:TextBox ID="txtphonenumber" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator Display = "Dynamic" ControlToValidate = "txtphonenumber" ID="revphone" ValidationExpression = "^[\s\S]{7,15}$" runat="server" ErrorMessage="Minimum 7 and Maximum 15 characters required."></asp:RegularExpressionValidator>
For More Info Refer this Below Link.....
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.