Ramaswamy
Ramaswamy

Reputation: 79

ASP.NET regular expression - validationExpression

I have a text box. I added a regular expression to validate the text box that can contain one or 20 characters as below

<asp:RegularExpressionValidator ID="regex" runat="server" 
     ErrorMessage="This contain pipe or more than 20 characters"  
     ValidationExpression="^.{1,20}$"
     ControlToValidate="txtRegexTester" >
</asp:RegularExpressionValidator>

I want to make sure the text box does not contain the PIPE (|) symbol also. How do I achieve both in one ValidationExpression?

Upvotes: 2

Views: 423

Answers (1)

Rapha&#235;l Althaus
Rapha&#235;l Althaus

Reputation: 60493

Something like this maybe (everything but pipe, 1 or 20 times)

"^[^|]{1,20}$"

Upvotes: 2

Related Questions