0

我正在尝试编写一个 RegularExpressionValidator 来检查以确保进入文本框的条目是整数(不包含“。”或“,”,只有整数值,如“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>

这有什么问题?我已经四处寻找,找不到任何原因导致这种情况没有很好地形成。

4

3 回答 3

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

"

于 2012-02-08T14:52:52.567 回答
0

尝试这个

<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> 
于 2012-02-08T14:58:36.247 回答
0

您的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).'
于 2012-02-08T14:52:44.410 回答