js屏蔽/過濾 特殊字符,輸入就刪除掉,實時刪除,


原文: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(); } } }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM