Search code examples
c#asp.netregexserver-tags

The Server Tag is not well formed - RegularExpressionValidator


I am trying to write a RegularExpressionValidator which checks to make sure the entry into a Textbox is Integer (does not contain "." or ",", only integer values like "500")

But I have encountered this:

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: The server tag is not well formed.

The code is as follows:

<asp:TextBox ID="Paymenttb" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID ="PaymentValidator" runat="server" ControlToValidate="Paymenttb" 
ErrorMessage="Payment must be of type Int (No "." or "," for example)." ValidationExpression="^\d+$">*</asp:RegularExpressionValidator>

What is the problem with this? I have searched around and cannot find any reason why this is not formed well.


Solution

  • ErrorMessage="Payment must be of type Int (No "." or "," for example)." 
    

    This part. You have quotes in your quoted parameter.

    You can go around that by making the outer quotes single quotes:

    ErrorMessage='Payment must be of type Int (No "." or "," for example).'
    

    Another solution: Escape the quote html-style:

    ErrorMessage="Payment must be of type Int (No &quot;.&quot; or &quot;,&quot; for example)." 
    

    "