Avatar of Bobby X
Bobby X
Flag for United States of America

asked on 

ASP.Net RegularExpression Validators


I am looking for a regular expression that validates to ensure that a min. of 2 and max. of 8 alpha characters (including spaces) are allowed without counting any leading and trailing spaces. Following regular expression doesn't seem to work (see ValidationExpression below).  Could someone please tell me what am I missing and provide a correct regex for this?

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtProductName" CssClass="ErrorMessage" Display="Dynamic" ValidationExpression="^[^\s]+[a-zA-Z\s]{2,8}[^\s]+$" ErrorMessage="Minimum 2 and maximum 8 characters allowed." SetFocusOnError="True" />

Many thanks in advance.

Regular ExpressionsASP.NET

Avatar of undefined
Last Comment
David H.H.Lee

8/22/2022 - Mon