java,php,asp.net,linux,javascript,mysql,mssql,oracle,编程

对非法字符进行过滤asp

转载请注明:http://www.pmjava.com/Article/ShowInfo.asp?ID=56665

函数说明:对非法字符进行过滤
'
这个函数将过滤所有非中文字符
function ClearString(str)
  
dim re,str1,str2,i
  
set re = new regexp

re.Pattern = "^[\u4e00-\u9fa5\s\n\r\t]+$"
  
for i=1 to len(str)
     str1
= mid(str,i,1)
     clearString
= re.Test(str1)
    
if clearString=true then
     str2
= str2&str1
    
end if
  
next
   str
=str2
   ClearString
= str
end function
function KillKey(str)
    KillKey
=str
end function

 

function SearchKey(str)
Key
="这里是非法字符 嘎嘎`~~CSDN也屏蔽的"
KeyArray
=split(Key,",")
K
=ubound(KeyArray)
str2
=ClearString(str)
for i=0 to K
   
if Instr(str2,KeyArray(i)) then
        response.Write(
"您所提交的信息中包含非法字符,请您返回后仔细检查所填写的内容然后再次提交您的信息!返回
感谢您的支持!
非法字符:
" & KeyArray(i))
        response.End()
   
end if
next
SearchKey
=str
end function
function urldecode(encodestr)   'encodestr就是要解码的字符串
Dim newstr,havechar,lastchar,i,char_c,next_1_c,next_1_Num
newstr
=""
havechar
=false
lastchar
=""
for i=1 to len(encodestr)
   char_c
=mid(encodestr,i,1)
  
if char_c="+" then
    newstr
=newstr & " "
  
elseif char_c="%" then
    next_1_c
=mid(encodestr,i+1,2)
    next_1_num
=cint("&H" & next_1_c)
  
   
if havechar then
     havechar
=false
     newstr
=newstr & chr(cint("&H" & lastchar & next_1_c))
   
else
    
if abs(next_1_num)<=127 then
      newstr
=newstr & chr(next_1_num)
    
else
      havechar
=true
      lastchar
=next_1_c
    
end if
   
end if
    i
=i+2
  
else
    newstr
=newstr & char_c
  
end if
next
urldecode
=newstr
end function




TempStr1
=urldecode(request.QueryString)
TempStr2
=urldecode(request.Form)
'查询提交的信息 如有非法字符 直接终止程序运行
SearchKey(TempStr1)
SearchKey(TempStr2)

posted on 2009-06-10 22:07 rrong_m 阅读(410) 评论(0)  编辑  收藏

<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

常用链接

随笔档案

文章分类

文章档案

java编程

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜