㈠ 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 我自己做的,希望對你有幫助