限制用户输入 [英] Restrict user input

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

问题描述

大家好,

i有一个文本字段,我希望用户只输入Y或N.


有人可以告诉我怎样才能限制用户输入任何其他字符,数字或特殊字符。

谢谢。

hi all,
i have a textfield where i would like the user to input only Y or N.

can somebody tell me how can i restrict the user from entering any
other character, number or special character.
thanks.

推荐答案

<sc*****@gmail.com>在消息中写道

news:11 ********************** @ z14g2000cwz.googlegr oups.com ...
<sc*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
大家好,
我有一个文本字段,我希望用户只输入Y或N.

有人可以告诉我如何限制用户输入任何
其他角色,数字或特殊字符。
谢谢。
hi all,
i have a textfield where i would like the user to input only Y or N.

can somebody tell me how can i restrict the user from entering any
other character, number or special character.
thanks.




这会有帮助吗?请注意自动换行。


< html>

< head>

< title> YN.htm< / title>

< script type =" text / javascript">

函数YN(那){

that.value = that.value.toUpperCase();

var rex = / ^ [YN]



Will this help? Watch for word-wrap.

<html>
<head>
<title>YN.htm</title>
<script type="text/javascript">
function YN(that) {
that.value = that.value.toUpperCase();
var rex = /^[YN]


/;

if(rex.test (that.value))返回;

alert(条目必须是Y或N.)

that.value ="" ;;

}

< / script>

< / head>

< body>

< form>

< input type =" text"命名= QUOT;文本" size =" 1"

maxlength =" 1" onchange =" YN(this)"

< / form>

< / body>

< / html> ;
/;
if (rex.test(that.value)) return;
alert("Entry must be Y or N only.")
that.value = "";
}
</script>
</head>
<body>
<form>
<input type="text" name="text" size="1"
maxlength="1" onchange="YN(this)">
</form>
</body>
</html>


你也可以查看onkeypress事件的文本框,只需删除

最后一个charectar和类似类型的pervious,如果他们的unicodes

不是Y和N的(在事件上,keyCode变量,假设函数

参数事件)

Also you can check the onkeypress event for the textbox, just delete
the last charectar and pervious ones of similar type if their unicodes
arent that of Y and N (on the event,keyCode varible, assuming function
argument event)


这篇关于限制用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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