Bobby X
asked on
ASP.Net RegularExpression Validators
Hi,
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.
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.
ASKER
None of your regex works.
The rule is: A minimum of 2 and a maximum of 8 Alpha characters (no numbers) and whitespaces in between the characters are allowed. For example, these are allowed:
"abcdefgh" - this has a maximum of 8 Alpha characters (no numbers)
"ab de gh" - this has a maximum of 8 Alpha characters (no numbers) w/ whitespaces in between
" abcdefgh " - this has a maximum of 8 Alpha characters (no numbers) with 1 or more leading & trailing spaces
" ab de gh " - this has a maximum of 8 Alpha characters (no numbers) w/ whitespaces in between but has 1 or more leading & trailing spaces
"ab" - this has a minimum of 2 Alpha characters (no numbers)
" ab " - this has a minimum of 2 Alpha characters (no numbers) with 1 or more leading & trailing spaces
The rule is: A minimum of 2 and a maximum of 8 Alpha characters (no numbers) and whitespaces in between the characters are allowed. For example, these are allowed:
"abcdefgh" - this has a maximum of 8 Alpha characters (no numbers)
"ab de gh" - this has a maximum of 8 Alpha characters (no numbers) w/ whitespaces in between
" abcdefgh " - this has a maximum of 8 Alpha characters (no numbers) with 1 or more leading & trailing spaces
" ab de gh " - this has a maximum of 8 Alpha characters (no numbers) w/ whitespaces in between but has 1 or more leading & trailing spaces
"ab" - this has a minimum of 2 Alpha characters (no numbers)
" ab " - this has a minimum of 2 Alpha characters (no numbers) with 1 or more leading & trailing spaces
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Open in new window
OrOpen in new window