导航:首页 > 净水问答 > js正则过滤危险字符

js正则过滤危险字符

发布时间:2022-06-06 20:25:51

1. 如何用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;
}

2. 怎么用Js正则表达式去除特殊字符

正则表达式只能去测试字符串适合符合,返回true,false。并不能改变你的字符串(也就是说去除功能)

3. 用JS怎么过滤 textarea 中的危险字符,如超链接<a></a>等

你可以写个正则表达式去匹配下TEXTAREA里面的那些标签 将标签去掉

4. Js字符串的正则匹配 如何过滤掉指定特征的字符串

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

5. 在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>

6. 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

7. 用JS如何写正则表达式 用了屏蔽用户输入的非法文字

var valid=/[!@#$%^&*()]/; //你认为哪个是非常字符就加进去
var input;
....

if(!valid.test(input)){
//错误信息
}

8. js用什么函数过滤非法字符防止跨站脚本攻击

test
如:抄<input type="text" id="txtceshi" /><input type="button" onclick="yanzheng()" value="ceshi" />
<script type="text/javascript">
function yanzheng() {
var ce = txtceshi.value;//获取文本框的值
var ze = /[^0-9]+/; //只能是数字,这里可以在网上找到一些正则替换成你想要的表达式
if (ze.test(ce)) {
alert("数据不合法!");
}
}
</script>

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

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

阅读全文

与js正则过滤危险字符相关的资料

热点内容
纯净水超滤设备 浏览:918
进过反渗透膜多少水是排掉的 浏览:811
污水泵维修后有振动是什么原因 浏览:678
lc型阳离子交换树脂 浏览:612
工厂焊烟净化器价格怎么样 浏览:720
锂电池半透膜和透析半透膜异同 浏览:818
蒸馏醋是否可以杀菌 浏览:984
什么叫做纯水车 浏览:637
生活污水生化池内填料有哪些 浏览:940
过滤器的pao检测 浏览:503
种什么植物治污水 浏览:649
莱芜哪里有处理废水的 浏览:112
17年科迪亚克空调滤芯怎么拆 浏览:555
老箱涵的污水如何截流 浏览:280
纳滤哪个品牌 浏览:519
污水预处理工艺怎么填写 浏览:107
蒸馏水是啥玩意 浏览:274
净水器哪个级别的好 浏览:134
昆山中空超滤膜怎样安装 浏览:144
牙齿磨损严重树脂修补 浏览:4