Text box validator:  min and max characters ASP.NET

arthurh88
arthurh88 used Ask the Experts™
on
  <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?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
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
Ryan ChongSoftware Team Lead

Commented:

Author

Commented:
i changed it to 10 but the textbox took even with 0
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

Author

Commented:
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}
Try with this too.....
 <asp:TextBox ID="txtInfo" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="rdvalie" runat="server" ControlToValidate="txtInfo"
            Display="Dynamic" ErrorMessage="Please enter a description between 10 and 400 characters"
            ValidationExpression="[\w\s]{10,50}" Style="position: relative;" Width="393px"
            Height="50px"></asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="txtInfo"
            Display="Dynamic" ErrorMessage="Please enter a description between 10 and 400 characters"
            ValidationExpression="[\w\s]{10,50}" Style="position: relative;" Width="393px"
            Height="50px"></asp:RegularExpressionValidator>


Thanks,

Author

Commented:
very smart idea.  combine with a required field.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial