導航:首頁 > 凈水問答 > 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正則過濾非法字元相關的資料

熱點內容
純凈水過濾器設備多少錢 瀏覽:776
現在從九台回長春用隔離嘛 瀏覽:377
4格過濾盒都放什麼 瀏覽:384
戴森凈化器黃色曲線代表什麼 瀏覽:95
農村污水治理都有哪些參考 瀏覽:10
水蒸氣蒸餾物質的量之比 瀏覽:540
進口ro濾芯什麼的好 瀏覽:995
鈉離子交換濃水 瀏覽:261
凈水器一直咕咕叫是什麼原因 瀏覽:136
凈水器tds值降多少算正常 瀏覽:22
煉汞蒸餾爐 瀏覽:831
水壺里邊有了水垢怎樣處理 瀏覽:89
買凈化器看什麼 瀏覽:86
凈水器濾芯一級是什麼 瀏覽:508
室外污水波紋管焊接參數 瀏覽:732
青島污水池膜結構蓋板多少錢 瀏覽:2
如何選擇客廳凈水器 瀏覽:530
整棟樓的污水主管道如何疏通 瀏覽:987
童衣樹脂四合扣 瀏覽:775
不銹鋼開水壺水垢怎麼清理 瀏覽:58