导航:首页 > 净水问答 > 条件过滤特殊字符

条件过滤特殊字符

发布时间:2020-12-21 10:32:23

㈠ JAVA特殊字符过滤方法

public static String StringFilter(String str) throws PatternSyntaxException {
// 只允许字母和数字
// String regEx = "[^a-zA-Z0-9]";
// 清除掉所有特殊字符
String regEx="[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(str);
return m.replaceAll("").trim();
}

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

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

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

㈣ 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

㈤ java过滤特殊字符的问题

"+"在URL中会被当作空格处理。
必须使用URLEncoder将其变成URL编码。
或者使用 javascript 的 encodeURIComponent(url) 函数对URL进行编码转换。

㈥ 如何过滤MAP中的特殊字符

//用来防页面来上输入的源带有破坏性内容
Map<String, String> map = new HashMap<String, String>();
map.put("1", "value1");
map.put("2", "value2");
map.put("3", "value3");
for(Iterator iterator = dataMap.entrySet().iterator(); iterator.hasNext();){
Map.Entry m = (Entry) iterator.next();
String mapValue = (String) m.getValue();
if("".equals(mapValue)||mapValue!=null){
String result = "";

//将取出的值进行相关操作然后再塞到Map里
......
m.setValue(result);
}
}

㈦ 如何过滤特殊字符和乱码的字符

这是编码引起的,把数据库表的那个字段编码改成utf-8格式 alter table user(表名) CHANGE old(老字段回) new(新字段) varchar(100) charset utf8 后面的语答句的编码就是utf8,不要改成utf-8,MySQL不识别,不用改字段名称就直接都写原来的字段名。

㈧ 求一个正则表达式过滤特殊字符但是不过滤@下划线之类的

这个的话也可以通过正则限定允许输入的字符来实现
比如说:字母开头6-15位字符就可以写成如下方式
/^[a-zA-Z][a-zA-Z0-9]{5,15}$/
这样也可以达到过滤特殊字符的效果

㈨ asp中如何过滤掉特殊字符

user=replace(trim(request.form("uName")),"'","''")
password=replace(trim(request.form("Password")),"'","''")
if instr(user,"%") or instr(user,"#") or instr(user,"?") or instr(user,"|") or instr(user,"'") then
response.write "<script language=javascript>alert('您的姓名含有非法字符!');this.location.href='login.asp';</script>"
response.end
end if

if instr(password,"%") or instr(password,"#") or instr(password,"?") or instr(password,"|") then
response.write "<script language=javascript>alert('您的密码含有非法字符!');this.location.href='login.asp';</script>"
response.end
end if 我自己做的,希望对你有帮助

阅读全文

与条件过滤特殊字符相关的资料

热点内容
净水器压力罐里水怎么能放掉 浏览:36
羚羊汽油滤芯怎么拆 浏览:578
用吸奶器吸怎么避免回奶 浏览:664
净水器代理哪里有卖的 浏览:351
树脂防滑垫去味 浏览:845
薄膜蒸发器有哪些种类污水浓缩 浏览:688
文华过滤函数用法 浏览:273
滤芯最大操作温度是多少 浏览:988
污水供应商有哪些 浏览:990
贵州进口家用污水提升器要多少钱 浏览:710
日处理十万吨污水处理厂需多少人 浏览:311
污水处理厂除臭系统厂家 浏览:867
RO膜进水要求铁锰 浏览:233
格美净水器怎么更换滤芯 浏览:719
活动义齿除垢 浏览:80
污水池盖去什么地方做 浏览:530
碧水源滤芯复位以后怎么设置 浏览:343
各种超滤膜优缺点 浏览:408
离子交换色谱分离蛋白质谁先 浏览:797
鱼缸滤芯脏东西怎么清除 浏览:881