如何允许一个文本框仅整数? [英] How to allow only integers in a textbox?

查看:156
本文介绍了如何允许一个文本框仅整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这篇关于如何允许一个文本框仅整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆