ASP.NET 2.0 RegularExpessionValidator to exclude a specific line.

Say you had the following select:

<select id="ItemSelect" runat="server">
 <option selected="selected">Select your item</option>
 <option>Item one</option>
 <option>Item two</option>
 <option>Item three</option>
</select>

And you wanted to force the user to select Item one/two/three. You could do this by creating a RegularExpressionValidator to to accept anything but the “Select your item” option like so:

<asp:RegularExpressionValidator ID="ItemRegularExpressionValidator" runat="server" ControlToValidate="ItemSelect"
                                ErrorMessage="Item Required" Text="*" SetFocusOnError="true" ValidationExpression="^((?!Select your item).)*$"></asp:RegularExpressionValidator>

No comments:

Post a Comment