Link to home
Start Free TrialLog in
Avatar of arthurh88
arthurh88

asked on

Text box validator: min and max characters ASP.NET

  <asp:RegularExpressionValidator ID="RegularExpressionValidator2" 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:RegularExpressionValidator>

This works for max characters, but how to make it work for minimum characters as well?
Avatar of krunal_shah
krunal_shah

Hi,

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
Avatar of Ryan Chong
Avatar of arthurh88

ASKER

i changed it to 10 but the textbox took even with 0
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}
ASKER CERTIFIED SOLUTION
Avatar of vora_bhaumik
vora_bhaumik
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
very smart idea.  combine with a required field.