arthurh88
asked on
Text box validator: min and max characters ASP.NET
<asp:RegularExpressionVali dator ID="RegularExpressionValid ator2" runat="server" ControlToValidate="txtInfo "
Display="Dynamic" ErrorMessage="Please enter a description between 10 and 400 characters"
ValidationExpression="[\s\ S]{1,400}" style="position: relative;" Width="393px" Height="50px"></asp:Regula rExpressio nValidator >
This works for max characters, but how to make it work for minimum characters as well?
Display="Dynamic" ErrorMessage="Please enter a description between 10 and 400 characters"
ValidationExpression="[\s\
This works for max characters, but how to make it work for minimum characters as well?
you can try use a custom validator instead.
http://www.w3schools.com/ASPNET/showasp.asp?filename=demo_customvalidator
http://www.w3schools.com/ASPNET/showasp.asp?filename=demo_customvalidator
ASKER
i changed it to 10 but the textbox took even with 0
ASKER
when the textbox has 0 characters in it, the error does not appear. the error appears with 1-9 characters.
Try this one...
[\w\s]{10,50}
[\w\s]{10,50}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
very smart idea. combine with a required field.
For minimum 10 chaacter you need to change 1 in your regex to 10,
[\s\S]{10,400}
check link below ,
http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/thread/e6411823-f932-4cc2-a8b3-e409df91ea68
Thanks