简体   繁体   English

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

[英]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") 我正在尝试编写一个RegularExpressionValidator,以检查以确保进入文本框的条目是Integer(不包含“。”或“,”,仅包含“ 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. 我四处搜寻,找不到任何无法正常形成的原因。

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: 另一个解决方案:转义html样式的引用:

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

"

Your ErrorMessage attribute is not well formed: 您的ErrorMessage属性格式不正确:

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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM