过滤特殊字符的js代码

发布时间:2020-12-21编辑:脚本学堂
分享一个过滤特殊字符的js代码,学习下js如何过滤特殊字符,有需要的朋友参考下。

例子,js脚本过滤特殊字符
 

复制代码 代码示例:
<script language="javascript">
function checkforms()
{
   var iu, iuu, regarray=new array("◎","■","●","№","↑","→","↓"+
   "!","@","#","$","%","^","&","*","(",")","_","-","+","=","|","","[","]","?","~","`"+
   "!","<",">","‰","→","←","↑","↓","¤","§","#","&","&","\","≡","≠"+
   "≈","∈","∪","∏","∑","∧","∨","⊥","‖","‖","∠","⊙","≌","≌","√","∝","∞","∮"+
   "∫","≯","≮",">","≥","≤","≠","±","+","÷","×","/","ⅱ","ⅰ","ⅲ","ⅳ","ⅴ","ⅵ","ⅶ","ⅷ","ⅹ","ⅻ","一","二"+
   "╄","╅","╇","┻","┻","┇","┭","┷","┦","┣","┝","┤","┷","┷","┹","╉","╇","【","】"+
   "三","四","五","六","七","八","九","十","①","②","③","④","⑤","⑥","⑦","⑧","⑨","⑩","┌","├","┬","┼","┍","┕","┗","┏","┅","—"+
   "〖","〗","←","〓","☆","§","□","‰","◇","^","@","△","▲","#","℃","※",".","≈","¢");
   iuu=regarray.length;
   var obj=document.getelementbyid("username");
   if(obj.value=="")
   {
     alert("用户名不能为空");
      obj.focus();
      return false;
   }
   for(iu=1;iu<=iuu;iu++)
   { 
      if(regarray[iu] !="")
       {
          if (obj.value.indexof(regarray[iu])!=-1)
           {
             alert("注册名不可以包含:" + regarray[iu]);
             document.gforms.username.focus();
             return false;
          }
        }
   }
   return true;            
}
</script>
<form method="post" onsubmit="return checkforms();">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
请输入用户名:<input type="text" name="username">
<input type="submit" name="submit" value="提交">
</form>

特殊字符过滤的效果图:
js过滤特殊字符

js 过滤特殊字符的简单例子
js正则过滤特殊字符
js过滤特殊字符的实现代码
js过滤特殊字符小例子
JavaScript 特殊字符示例
js过滤特殊字符的正则表达式
js过滤特殊字符输入
js特殊字符过滤函数代码
js验证特殊字符的例子
js特殊字符转义方法
js判断是否包含特殊字符
JS过滤url参数中的特殊字符
js过滤特殊字符(js正则表达式)