如何限制用户不要在文本框中输入其他数字 [英] how to restrict user not to enter other numbers in textbox

查看:71
本文介绍了如何限制用户不要在文本框中输入其他数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何限制用户不要在文本框中输入除12以外的其他数字。

========================= ================================





i我的网页上有一个文本框,用户只能输入此文本框中的数字12。



如果他输入其他数字,则必须显示错误。



请给我一个很好的解决方案。顺便说一下我在asp.net c#上工作。



Hlep me!提前谢谢

how to restrict user not to enter other numbers in textbox except 12.
=========================================================


i have a textbox on my webpage the user should enter only the number 12 in this textbox.

if he enters other number, it must shows a error .

Please give me good solution. by the way am working on asp.net c#.

Hlep me ! thank you in advance

推荐答案

最简单的方法是处理 keydown [ ^ ]活动,只允许输入12个。



其他一些可能提供一些见解的文章 -

http://help.dottoro.com/ljlkwans.php [ ^ ]

http://blog.pothoven.net/2008/05/keydown-vs-keypress-in-javascript.html [ ^ ]
The easiest would be to handle the keydown[^] event and only allow 12 to be entered.

Some other articles that might provide some insight -
http://help.dottoro.com/ljlkwans.php[^]
http://blog.pothoven.net/2008/05/keydown-vs-keypress-in-javascript.html[^]


您可以限制用户输入除数字或任何标准以外的任何字符ticular字符集。看看这篇文章。它讨论了类似的技术。



一个用于常见验证方案的小型Javascript框架。 [ ^ ]



它会像



You can restrict the user to enter any characters other than numbers or any particular set of characters. Check out this article. it talks about a technique to so the similar thing.

A Tiny Javascript Framework for Common Validation Scenarios.[^]

it would be something like

<asp:TextBox ID="TextBox7" runat="server" onkeypress="return AcceptRegExOnly(event, /^(1|2)


/); MaxLength = 2 > < / asp:TextBox >
/);" MaxLength="2"></asp:TextBox>





使用此框架。这里唯一的问题是11和22也被接受,但可以通过使用正确的正则表达式来规避。



using this framework. the only catch here is that 11 and 22 are also accepted but that can be circumvented by using a proper regex.


这篇关于如何限制用户不要在文本框中输入其他数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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