2015-08-20 59 views
1

我要检查客户端写整型在我的文本框,所以我写我这样的代码:文本框整数验证错误

<td class="style2"> 
<asp:TextBox ID="phonetxt" runat="server" Height="22px" MaxLength="10" 
Width="158px"></asp:TextBox> 
</td> 
<td> 
<asp:RequiredFieldValidator ID="PhoneRequiredFieldValidator" runat="server" ForeColor="Red" ControlToValidate="phonetxt" ErrorMessage="...."></asp:RequiredFieldValidator> 
<asp:RegularExpressionValidator ID="RegularExpressionValidator6" runat="server" Display="None" ErrorMessage="Accepts only numbers." ControlToValidate="phonetxt" ValidationExpression=""^[0-9]*$" Text="*"></asp:RegularExpressionValidator> 
</td> 

但有错误发生这样的:

Server Error in '/' Application.
Parser Error

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.
Source Error: Line 153: Line 154: Line 155: Line 156: Line 157:

Source File: /account.aspx Line: 155

什么shold我现在做?有没有更好的方法来检查?

回答

1

更换

ValidationExpression=""^[0-9]*$" 

ValidationExpression="^[0-9]*$" 
+0

感谢它现在的工作,但它没有显示任何错误,当我写错误的值!!!!有什么问题? –

+0

一个'''需要在文本内转义 - 所以你需要写''''' – fubo

0

基础上的错误。 你忘了在这个

asp:RequiredFieldValidator ID="PhoneRequiredFieldValidator" runat="server" ForeColor="Red" ControlToValidate="phonetxt" ErrorMessage="...."></asp:RequiredFieldValidator> 

<你缺少这样的开放...

对于ValidationExpression=""^[0-9]*$"
如果你真的需要有“把一个逃脱它,所以它成为

ValidationExpression="\"^[0-9]*$"