简体   繁体   中英

The Server Tag is not well formed - RegularExpressionValidator - parse error

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 '&quot'. 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= "^[^'&quot]+$" /> 

Used a different approach to resolve this issue. Replace double quotes(") inside the expression with '&quot';

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM