导航:首页 > 净水问答 > js过滤指定字符

js过滤指定字符

发布时间:2023-08-13 08:32:17

A. js中用正则表达式 过滤特殊字符 校验所有输入域是否含有特殊符号

楼上2位已经说的很明白了,只允许输入规定的字符,如果输入含有其他字符就直接提示,不允许输入特殊字符,或者直接给它替换掉。

B. js 如何过滤div里内的指定字符

String.replace(正则表达式,"")
replace是string类型内置的替换方法,第一个参数可以是正则表达式,第二个参数是版想要权替换成的文本,正则中可以使用/g来表示替换所有匹配的文本,不使用则代表只替换匹配到的第一个字符对象,将第二个参数设为空字符串便可达到过滤的效果。
具体正则需要你自己去了解关于正则的知识了,祝你好运。

C. 在javascript中用正则表达式过滤指定的字符(一定要能指定!)

楼上的不加转义字符\ 你们搞什么啊
正确的应该是这样的

加入你得到的内字符窜容为 name
<html>
<head>
<script>
function test1(){
var name=document.getElementById('user').value;
name=name.replace(/(\!+)|(\<+)|(\>+)|(\'+)/g,"");
alert(name);
}
</script>
</head>

<body>
<input type="text" id="user" />
<input type="button" value="te" onclick="test1()">
</body>
</html>

D. js字符过滤

先将表单的字段值送入一个字符串答握变量清信庆中,如str。
然后str.indexOf("字坦腔眼")>0,屏蔽它。

E. js 正则过滤特殊字符

您好

js检查是否含有非法字符,js 正则过滤特殊字符

//正则
functiontrimTxt(txt){
returntxt.replace(/(^s*)|(s*$)/g,"");
}

/**
*检查是否含有非法字符
*@paramtemp_str
*@returns{Boolean}
*/
functionis_forbid(temp_str){
temp_str=trimTxt(temp_str);
temp_str=temp_str.replace('*',"@");
temp_str=temp_str.replace('--',"@");
temp_str=temp_str.replace('/',"@");
temp_str=temp_str.replace('+',"@");
temp_str=temp_str.replace(''',"@");
temp_str=temp_str.replace('\',"@");
temp_str=temp_str.replace('$',"@");
temp_str=temp_str.replace('^',"@");
temp_str=temp_str.replace('.',"@");
temp_str=temp_str.replace(';',"@");
temp_str=temp_str.replace('<',"@");
temp_str=temp_str.replace('>',"@");
temp_str=temp_str.replace('"',"@");
temp_str=temp_str.replace('=',"@");
temp_str=temp_str.replace('{',"@");
temp_str=temp_str.replace('}',"@");
varforbid_str=newString('@,%,~,&');
varforbid_array=newArray();
forbid_array=forbid_str.split(',');
for(i=0;i<forbid_array.length;i++){
if(temp_str.search(newRegExp(forbid_array[i]))!=-1)
returnfalse;
}
returntrue;
}

---------------------

作者:dongsir 董先生

来源:董先生的博客

原文链接:js检查是否含有非法字符

版权声明:本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。转载时请标注:http://dongsir.cn/p/195

F. 如何用js或则jquery过滤特殊字符

1、jQuery使用正则匹配替换特殊字符

functionRegeMatch(){
varpattern=newRegExp("[~'!@#$%^&*()-+_=:]");
if($("#name").val()!=""&&$("#name").val()!=null){
if(pattern.test($("#name").val())){
alert("非法字符!");
$("#name").attr("value","");
$("#name").focus();
returnfalse;
}
}
}

2、jQuery限制输入ASCII值

//数字0-9的ascii为48-57
//大写A-Z的ascii为65-90
//小写a-z的ascii为97-122

//----------------------------------------------------------------------
//<summary>
//限制只能输入数字和字母
//</summary>
//----------------------------------------------------------------------
$.fn.onlyNumAlpha=function(){
$(this).keypress(function(event){
vareventObj=event||e;
varkeyCode=eventObj.keyCode||eventObj.which;
if((keyCode>=48&&keyCode<=57)||(keyCode>=65&&keyCode<=90)||(keyCode>=97&&keyCode<=122))
returntrue;
else
returnfalse;
}).focus(function(){
this.style.imeMode='disabled';
}).bind("paste",function(){
varclipboard=window.clipboardData.getData("Text");
if(/^(d|[a-zA-Z])+$/.test(clipboard))
returntrue;
else
returnfalse;
});
};


//-----调用方法$("#文本框id").onlyNumAlpha();


3、js正则匹配过滤

functionstripscript(s)
{
varpattern=newRegExp("[`~!@#$^&*()=|{}':;',\[\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]")
varrs="";
for(vari=0;i<s.length;i++){
rs=rs+s.substr(i,1).replace(pattern,'');
}
returnrs;
}

G. 简单的用js实现过滤多余字符的正则表达式

利用正则表达法除去字符串中的重复字符
str
=
"Google"
str1
=
str.replace(/(.).*\1/g,"$1")
document.write(str
+
"
");
document.write(str1);
[Ctrl+A
全选
注:如需引入外部Js需刷新才能执行]

阅读全文

与js过滤指定字符相关的资料

热点内容
亚克力镜片会比树脂镜片好吗 浏览:50
北大口腔树脂贴面 浏览:828
计算理论离子交换容量 浏览:3
两台污水泵一主一备如何接浮球 浏览:866
污水处理补贴企业所得税 浏览:985
高效治水微生物菌剂水处理微生物 浏览:17
污水处理厂cod怎么测氧 浏览:715
超滤膜截留单范围 浏览:632
没有长的吸管怎么做饮水机 浏览:686
没有提前预留净水机管线怎么办 浏览:435
制豆腐的废水 浏览:602
河南信阳地区污水处理 浏览:750
饮水机去水垢怎么去 浏览:402
污水井堵塞的报告 浏览:764
离子交换树脂如何净水 浏览:933
漳州市区污水处理收费标准 浏览:409
半透膜选择透过性么 浏览:963
污水处理含油浮渣怎么处理 浏览:145
发动机空气滤芯忘安了什么后果 浏览:823
废水温度 浏览:757