服务器标记的格式不正确-RegularExpressionValidator

本文关键字:不正确 -RegularExpressionValidator 格式 服务器 | 更新日期: 2023-09-27 18:23:51

我正在尝试编写一个RegularExpressionValidator,它检查以确保文本框中的条目是Integer(不包含"."或",",只有像"500"这样的整数值)

但我遇到了这个:

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.

代码如下:

<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>

这有什么问题?我到处找了找,找不到任何原因造成这种情况不好。

服务器标记的格式不正确-RegularExpressionValidator

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

这部分。您的带引号的参数中有引号。

你可以通过将外引号做成单引号来绕过这一点:

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

另一个解决方案:转义html样式:

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

"

您的ErrorMessage属性格式不正确:

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

您需要转义属性值中的",方法是将它们加倍:

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

或者,使用单引号分隔属性值:

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

试试这个

<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> 

<asp:RegularExpressionValidator ID ="PaymentValidator" runat="server" ControlToValidate="Paymenttb"  ErrorMessage="Payment must be of type Int (No '.' or ',' for example)." ValidationExpression="[0-9]"></asp:RegularExpressionValidator>