導航:首頁 > 凈水問答 > c正則過濾非法字元

c正則過濾非法字元

發布時間:2023-03-03 23:54:21

Ⅰ jsp中如何過濾非法字元

可以利用javascript驗證正則表達式的方式對非法字元做處理,同樣Java也可以利用正則表達式幫你過濾非法字元,最終還得更具你的具體需求來定。

Ⅱ 在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>

Ⅲ 幾種過濾URL和FORM中非法字元的方法

ASP過濾URL和FORM中非法字元第一種:<%'檢查URL輸入限制非法字元url=LCase(request.querystring())ip=request.ServerVariables(
REMOTE_ADDR)pos1=instr(url,%)pos2=instr(url,')pos3=instr(url,;)pos4=instr(url,where)pos5=instr(url,select)pos6=instr(url,chr)pos7=instr(url,/)pos8=Instr(url,and)ifpos1<0orpos2<0orpos3<0orpos4<0orpos5<0orpos6<0orpos7<0orpos8<0thenresponse.Write
你嘗試使用危險字元,系統已經對此做了記錄如下您的IP:&ip&操作時間:&date()&
response.End()endif'檢查表單輸入,限制非法字元'使用request.QueryString來索引request的所有資料,作為SQL檢查之用'如出現非法字元則自動停止輸出fori_request=1torequest.form.Countifinstr(request.form(i_request),')<0orinstr(request.form(i_request),;)<0thenResponse.Write
<scriptlanguage='javascript'history.back();alert('你嘗試使用危險字元,系統已經對此做了記錄如下您的IP:&ip&操作時間:&date()&
');</script
response.End()endifnext%第二種:<%OnErrorResumeNextdimsql_injdata,sql_inj,sql_get,sql_data
SQL_injdata='|oxSQL_inj=split(SQL_Injdata,|)'定義過濾字元,可以自己添加,以|分隔''|;|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare'對post方式過濾IfRequest.Form<ThenForEachSql_PostInRequest.FormForSQL_Data=0ToUbound(SQL_inj)ifinstr(Request.Form(Sql_Post),Sql_Inj(Sql_DATA))0ThenResponse.redirectss'出錯時轉向頁面
Response.endendifnextnextendif'對GET方式過濾IfRequest.QueryString<ThenForEachSQL_GetInRequest.QueryStringForSQL_Data=0ToUbound(SQL_inj)ifinstr(Request.QueryString(SQL_Get),Sql_Inj(Sql_DATA))0ThenResponse.redirectss'出錯時轉向頁面
Response.endendifnextNextEndIf%第三種:functioncheckstr(str)'過濾非法字元函數dimtempstrifstr=thenexitfunctiontempstr=replace(str,
chr(34),)'tempstr=replace(tempstr,
chr(39),)''tempstr=replace(tempstr,
chr(60),)'<tempstr=replace(tempstr,
chr(62),)'tempstr=replace(tempstr,
chr(37),)'%tempstr=replace(tempstr,
chr(38),)'&tempstr=replace(tempstr,
chr(40),)'(tempstr=replace(tempstr,
chr(41),)')tempstr=replace(tempstr,
chr(59),)';tempstr=replace(tempstr,
chr(43),)'+tempstr=replace(tempstr,
chr(45),)'-tempstr=replace(tempstr,
chr(91),)'[tempstr=replace(tempstr,
chr(93),)']tempstr=replace(tempstr,
chr(123),)'{tempstr=replace(tempstr,
chr(125),)'}checkstr=tempstrendfunction第四種:'================================================'函數名:IsValidStr'作用:判斷字元串中是否含有非法字元'參數:str----原字元串'返回值:False‚True-----布爾值'================================================PublicFunctionIsValidStr(ByValstr)IsValidStr=(str)ThenExitFunctionIfTrim(str)=‚iForbidStr=
and|chr|:|=|%|&|$|#|@|+|-|*|/|/|<||;|‚|^|&Chr(32)&|&Chr(34)&|&Chr(39)&|&Chr(9)ForbidStr=Split(ForbidStr‚|)Fori=0ToUBound(ForbidStr)IfInStr(1‚str‚ForbidStr(i)‚1)0ThenIsValidStr==TrueEndFunctionASP.(Stringpara)//過濾非法字元{intflag=0;flag+=para.indexOf(')+1;flag+=para.indexOf(;)+1;flag+=para.indexOf(1=1)+1;flag+=para.indexOf(|)+1;flag+=para.indexOf(<)+1;flag+=para.indexOf()+1;if(flag!=0){System.
out
提交了非法字元!!!);returnfalse;}returntrue;}

Ⅳ 過濾網頁上輸入的非法字元,從網上找了段js代碼,但是發現我用中文輸入時就逃過了過濾,這個該怎麼解決呢

因為中文輸入的特殊字元已經失去了特殊控制意義,所以程序沒有過濾中文輸入的這些符號,如果你中文的符號也不放過,那麼需要修改下面這個語句:
var txt=new RegExp("[ ,\\`,\\~,\\!,\\@,\#,\\$,\\%,\\^,\\+,\\*,\\&,\\\\,\\/,\\?,\\|,\\:,\\.,\\<,\\>,\\{,\\},\\(,\\),\\',\\;,\\=,\"]");

例如增加過濾@符號的的語句如下:
var txt=new RegExp("[ ,\\`,\\~,\\!,\\@,\#,\\$,\\%,\\^,\\+,\\*,\\&,\\\\,\\/,\\?,\\|,\\:,\\.,\\<,\\>,\\{,\\},\\(,\\),\\',\\;,\\=,\"@]");

添加到]前面就可以了,好像轉換了中文和英文的符號,你在記事本裡面修改程序代碼的時候注意區別。

閱讀全文

與c正則過濾非法字元相關的資料

熱點內容
亞摩斯凈水器濾芯怎麼換 瀏覽:115
壁掛太陽能如何除垢 瀏覽:440
蒸餾反應超溫時一定超壓么 瀏覽:229
大慶煉化第三污水廠簡介 瀏覽:1
魚缸換水過濾泵停嗎 瀏覽:584
強酸性陽離子交換樹脂會吸水嗎 瀏覽:833
10寸平口超濾膜是否需要反沖洗 瀏覽:919
柴油機濾芯爆裂怎麼回事 瀏覽:413
粉末聚酯樹脂有什麼書 瀏覽:270
高鹽廢水處理工藝 瀏覽:279
醋酸乙烯酯蒸餾 瀏覽:502
豹王柴機油濾芯質量怎麼樣 瀏覽:148
靜脈血經過幾次過濾變動脈血 瀏覽:402
生活污水處理監測 瀏覽:254
罐頭加工廠廢水 瀏覽:448
句容污水招標 瀏覽:811
純水機設備電導率怎麼調 瀏覽:943
反滲透超濾膜怎麼處理 瀏覽:853
浙江洗瓶機濾芯怎麼選 瀏覽:210
純水處理耗電多少 瀏覽:384