導航:首頁 > 凈水問答 > 名稱特殊字元過濾

名稱特殊字元過濾

發布時間:2020-12-30 22:33:05

Ⅰ 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;
}

Ⅲ php獲取微信昵稱時如何過濾特殊字元

用個函數過濾掉特殊字元

/** * $str 微信昵稱 **/ public function filter($str) { if($str){ $name = $str; $name = preg_replace('/\xEE[\x80-\xBF][\x80-\xBF]|\xEF[\x81-\x83][\x80-\xBF]/', '', $name); $name = preg_replace('/xE0[x80-x9F][x80-xBF]『.『|xED[xA0-xBF][x80-xBF]/S','?', $name); $return = json_decode(preg_replace("#(\\\ud[0-9a-f]{3})#ie","",json_encode($name))); if(!$return){ return $this->jsonName($return); } }else{ $return = ''; } return $return; }

Ⅳ 如何過濾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不識別,不用改欄位名稱就直接都寫原來的欄位名。

Ⅵ 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

Ⅶ jQuery 過濾html標簽屬性的特殊字元

您好,如果在表單中需要提交一字元串,其中包含,< > " &字元時,當我們把這字元串顯示到jsp頁面時,會和html標簽產生沖突,導致web頁面的某些部分消失或者格式不正確。為了解決以上問題,需要在顯示之前,對字元串進行代碼過濾。
把字元串中的 < 替換為 &It;
> 替換為 >
" 替換為 "
& 替換為 &
這里給出一個靜態的過濾代碼,供大家參考:
public class StringUtils {
/**
* This method takes a string which may contain HTML tags (ie, <b>,
* <table>, etc) and converts the '<'' and '>' characters to their HTML escape sequences.
* @param input the text to be converted.
* @return the input string with the characters '<' and '>' replaced with their HTML escape sequences.
*/
public static final String escapeHTMLTags(String input) {
//Check if the string is null or zero length -- if so, return
//what was sent in.
if (input == null || input.length() == 0) {
return input;
}
//Use a StringBuffer in lieu of String concatenation -- it is
//much more efficient this way.
StringBuffer buf = new StringBuffer(input.length());
char ch = ' ';
for (int i = 0; i < input.length(); i++) {
ch = input.charAt(i);
if (ch == '<') {
buf.append("<");
}
else if (ch == '>') {
buf.append(">");
}else if(ch == '"'){
buf.append(""");
}else if(ch == '&'){
buf.append("&");
}
else {
buf.append(ch);
}
}
return buf.toString();
}
}
此時,只需在jsp中對字元串調用此方法(StringUtils.escapeHTMLTags(str))即可。

Ⅷ java正則表達式過濾特殊字元

Stringregexp="[^'"%]*";
Stringstring="abc%";
System.out.println(string.matches(regexp));

Ⅸ 求一個正則表達式過濾特殊字元但是不過濾@下劃線之類的

這個的話也可以通過正則限定允許輸入的字元來實現
比如說:字母開頭6-15位字元就可以寫成如下方式
/^[a-zA-Z][a-zA-Z0-9]{5,15}$/
這樣也可以達到過濾特殊字元的效果

閱讀全文

與名稱特殊字元過濾相關的資料

熱點內容
賓士221的機油濾芯是什麼形狀 瀏覽:23
純水機廢水管15米長有影響嗎 瀏覽:11
超濾膜能否截留cod 瀏覽:127
除垢除焦劑公司 瀏覽:21
印染廢水格柵 瀏覽:263
化學鎳廢水的COD 瀏覽:58
LX過濾器 瀏覽:599
淘寶檸檬酸除垢劑好評語 瀏覽:170
糞便污水處理備注填什麼 瀏覽:365
如何養殖污水糞便 瀏覽:25
污水井流水 瀏覽:548
中持水務污水處理 瀏覽:483
車載污水真空泵多少錢一台 瀏覽:759
馬桶提升器好用嗎 瀏覽:32
高壓清洗污水多少錢 瀏覽:673
除塵器提升缸工作原理 瀏覽:703
增福康凈水器不制水是怎麼回事 瀏覽:305
食鹽水可以除去水垢嗎 瀏覽:714
聚氫乙稀樹脂是什麼形狀 瀏覽:684
好事近凈水機怎麼樣 瀏覽:935