2

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?

1 Answer 1

2

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

"^[^|]{1,20}$"
Sign up to request clarification or add additional context in comments.

1 Comment

This probably has better performance than my answer! One note: you don't need to escape the | in a character class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.