I'm trying to write a regular expression to check if it contains alphanumeric characters and can include all special characters except single and double quotes. I have used a regular expression validator but it gives a parse error.
<asp:RegularExpressionValidator ID="revPrompt"
runat="server"
ControlToValidate="txtPrompt"
Display="Dynamic"
ErrorMessage="Prompts cannot include single or double quotes, but all other special characters are allowed"
ForeColor="Red"
SetFocusOnError="true"
Text="*"
ValidationExpression= "^[^'"]+$" />
I tried with several validation expression by doubling the "(double quotes. eg: ValidationExpression= "^[^'""]+$"). But nothing worked. Can someone please tell what is the mistake in my code?
Thanks.
That is an XML file, and you are trying to include a " in an attribute. It needs to be replaced with '"'. EG:
<asp:RegularExpressionValidator ID="revPrompt"
runat="server"
ControlToValidate="txtPrompt"
Display="Dynamic"
ErrorMessage="Prompts cannot include single or double quotes, but all other special characters are allowed"
ForeColor="Red"
SetFocusOnError="true"
Text="*"
ValidationExpression= "^[^'"]+$" />
Used a different approach to resolve this issue. Replace double quotes(") inside the expression with '"';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.