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

条件过滤特殊字符

发布时间: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 我自己做的,希望对你有帮助

阅读全文

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

热点内容
污水进水总磷高是什么原因 浏览:575
家里地暖不热过滤阀 浏览:880
含氰废水降低ph 浏览:157
小米净化器pro数据怎么看 浏览:139
废水的ss值 浏览:693
小区室外雨污水管道图纸怎么看 浏览:554
污水井剖面图尺寸 浏览:588
安利净水器滤芯外面的膜是什么 浏览:308
酒店的净水器是怎么用的 浏览:338
除污水为什么要预氧化 浏览:674
小米车载净化器怎么走线 浏览:296
为什么打开回水阀排出来污水 浏览:412
纯净水桶子有刻划怎么办 浏览:827
蒸馏饼的做法 浏览:171
蒸馏水存在丁达尔效应吗 浏览:10
空气净化器为什么会有一股味道 浏览:366
缺氧污水泉怎么发现 浏览:939
2013款英朗gt汽油滤芯什么牌子的 浏览:145
为什么要用蒸馏水清洗 浏览:853
小型生活污水净化槽 浏览:768