0

I'd like to use a asp:RegularExpressionValidator where the ValidatorExpression is a regex that matches all strings that do not contain an ampersand. Google fu didn't yield much, but I'm sure it's probably not too complicated.

<asp:RegularExpressionValidator
   ID="StringValidator1"
   runat="server"
   ControlToValidate="textBox1"
   ValidationExpression="???"
   Display="Dynamic"
   ErrorMessage="String cannot contain ampersands"
   ValidationGroup="Group1"
/>

Thanks.

2 Answers 2

3
ValidationExpression = "^[^&]*$"

matches any string that doesn't contain an ampersand.

Explanation:

^      # Start of string
[^&]*  # Any number of characters that are not ampersands
$      # End of string
Sign up to request clarification or add additional context in comments.

Comments

1

Your regex will be

^[^&]+$

Means everything except &

Comments

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.