允许用户在文本框中仅输入0或1 [英] allow user to enter only 0 or 1 in textbox

查看:80
本文介绍了允许用户在文本框中仅输入0或1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

允许用户在文本框中只输入0或1的单个数字。



帮助我们,谢谢。

allow user to enter only a single digit of 0 or 1 in textbox.

help me guys, thanks.

推荐答案

使用 AJAX FilteredTextBoxExtender Control [ ^ ]如下:
<asp:textbox id="TextBox1" runat="server"></asp:textbox>

<cc1:filteredtextboxextender id="FilteredTextBoxExtender1"  runat="server" validchars="10" targetcontrolid="TextBox1" >
</cc1:filteredtextboxextender>



问候..


Regards..


使用 KeyPress 事件。



例如。



Use KeyPress event.

Eg.

protected void YourTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
    var allowKeys = new[] { Keys.Back, Keys.D0, Keys.D1 };
    e.Handled = !allowKeys .Contains((Keys)e.KeyChar);
}





我希望它会对你有所帮助。


$ b $祝你好运。



I hope It will help you.

Good luck.


这篇关于允许用户在文本框中仅输入0或1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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