如何允许一个文本框仅整数?

问题描述:

在我的表单我想允许整数值的类型只在一个文本框。那怎么办?

In my form I want to allow typing of integer values only in a textbox. How to do that?

您可以使用RegularEx pressionValidator这一点。下面是样本code:

You can use RegularExpressionValidator for this. below is the sample code:

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="TextBox1" runat="server" ErrorMessage="Only Numbers allowed" ValidationExpression="\d+"></asp:RegularExpressionValidator>

以上文本框只允许整数因为在RegularEx pressionValidator输入有场名为ValidationEx pression,这验证了文本框。但是,您可以修改按照您的要求。

above TextBox only allowed integer to be entered because in RegularExpressionValidator has field called ValidationExpression, which validate the TextBox. However, you can modify as per your requirement.