2012-02-08 51 views
0

我正在尝试编写一个RegularExpressionValidator,它检查以确保输入到文本框是整数(不包含“。”或“,”,只有像“500” )服务器标签格式不正确 - RegularExpressionValidator

但我也遇到过这样的:

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> 

这有什么问题吗? 我搜索了四周,找不到任何理由为什么这种形式不好。

+1

你的错误信息中包含'“'这是不允许的 – Shai 2012-02-08 14:51:32

回答

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

"

+0

我不能相信我没有看到!什么是业余的错误。非常感谢。将标记为答案。我认为我刚刚查看代码的时间太长了。 – Mac 2012-02-08 14:58:48

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

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> 
相关问题