Question

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.

Was it helpful?

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)." 

"

OTHER TIPS

Your ErrorMessage attribute is not well formed:

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

You need to escape the " in the attribute value - do that by doubling them:

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

Or, use single quotes to delimit the attribute value:

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

Try This

<asp:TextBox ID="Paymenttb" runat="server"></asp:TextBox>


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

OR

<asp:RegularExpressionValidator ID ="PaymentValidator" runat="server" ControlToValidate="Paymenttb"  ErrorMessage="Payment must be of type Int (No '.' or ',' for example)." ValidationExpression="[0-9]"></asp:RegularExpressionValidator> 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top