如果是汉字的话就自动清除怎么判断?
[code="html"]
function onk(obj){ if((/[\u4e00-\u9fa5]+/).test(obj)){ alert("不能含有汉字!"); txt = document.getElementById("inputId"); txt.value=""; txt.focus(); } }
[/code]
正则表达式
首先在输入框添加keydown事件 然后在这个事件里面判断输入的字符是不是在A-z0-9以及所有的允许输入的标点符号 如果不是就删除就好了
网上找找吧 好多了 我实在懒得写正则
表单中不允许输入中文:
[code="javascript"]
[/code]
[code="html"]不能输入中文汉字:
不能输入中文汉字,中文标点符号,全角:[/code]
function onk(obj){ if((/[\u4e00-\u9fa5]+/).test(obj)){ alert("不能含有汉字!"); txt = document.getElementById("inputId"); txt.value=""; txt.focus(); } }