Javascript实现禁止输入中文或英文的例子
本教程教你如何使用Javascript限制输入英文,或限制输入中文。
禁止输入英文:
<inputtype="text"onkeypress="returnevent.keyCode>=48&&event.keyCode<=57||(this.value.indexOf('.')<0?event.keyCode==46:false)"onpaste="return!clipboardData.getData('text').match(/\D/)"ondragenter="returnfalse">
用正则表达式限制只能输入中文:
<inputtype="text"onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')"onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))"/>
1.用正则表达式限制只能输入全角字符:
<inputtype="text"onkeyup="value=value.replace(/[^\uFF00-\uFFFF]/g,'')"onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\uFF00-\uFFFF]/g,''))"/>
2.用正则表达式限制只能输入数字:
<inputtype="text"onkeyup="value=value.replace(/[^\d]/g,'')"onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"/>
3.用正则表达式限制只能输入数字和英文:
<inputtype="text"onkeyup="value=value.replace(/[\W]/g,'')"onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"/>
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短