原文:http://niuxiaoxia870563296.iteye.com/blog/1828189
1.替换方法:
<input type="text" class="domain" onkeyup="this.value=this.value.replace(/[^\u4e00-\u9fa5\w]/g,‘‘)" ;this.value=this.value.replace(/[^\u4e00-\u9fa5\w]/g,‘‘)
2.输入之后立即清除:
//验证输入框内不能输入特殊字符,输入就立刻清除function cleanSpelChar(th){ ???if(/["‘<>%;)(&+]/.test(th.value)){ ?????????$(th).val(th.value.replace(/["‘<>%;)(&+]/,"")); ???}}
3.如果是特殊字符,禁止输入:
//验证输入框内不能输入特殊字符,输入前先作判断function processSpelChar(){ ???var code; ???var character; ???if(document.all){ ???????code = window.event.keyCode; ???}else{ ???????code = arguments.callee.caller.arguments[0].which; ???} ???var character = String.fromCharCode(code); ???var txt = new RegExp(/["‘<>%;)(&+]/); ???if(txt.test(character)){ ???????if(document.all){ ???????????window.event.returnValue = false; ???????}else{ ???????????arguments.callee.caller.arguments[0].preventDefault(); ???????} ???}}
js屏蔽/过滤 特殊字符,输入就删除掉,实时删除,
原文地址:https://www.cnblogs.com/mmzuo-798/p/9686006.html