我自己写的两个函数,我也常常用,一个是检是不是整形数字的,过程如下:返回值是true 或是 false
Rem ************检查是否为整数****************
Public Function IsInt(Str)
dim TempNum,TemStr
Str = Trim(Str)
IsInt = True
If Str = "" Or IsNull(Str) then
IsInt = False
Exit Function
End if
For TempNum = 1 To Len(Str)
if Not IsNumeric(mid(Str,TempNum,1)) then
IsInt = False
exit for
end if
next
End Function
一个过滤SQL注入的过程:
Rem *******************检查SQL的安全语言***********************
Function CheckStr(byVal ChkStr) '检查无效字符
Dim Str:Str=ChkStr
Str=Trim(Str)
If IsNull(Str) Then
CheckStr = ""
Exit Function
End If
Dim re
Set re=new RegExp
re.IgnoreCase =True
re.Global=True
re.Pattern="(\r\n){3,}"
Str=re.Replace(Str,"$1$1$1")
Set re=Nothing
Str = Replace(Str,"'","''")
Str = Replace(Str, "select", "select")
Str = Replace(Str, "join", "join")
Str = Replace(Str, "union", "union")
Str = Replace(Str, "where", "where")
Str = Replace(Str, "insert", "insert")
Str = Replace(Str, "delete", "delete")
Str = Replace(Str, "update", "update")
Str = Replace(Str, "like", "like")
Str = Replace(Str, "drop", "drop")
Str = Replace(Str, "create", "create")
Str = Replace(Str, "modify", "modify")
Str = Replace(Str, "rename", "rename")
Str = Replace(Str, "alter", "alter")
Str = Replace(Str, "cast", "cast")
CheckStr=Str
End Function
有两这个过程就OK了,
如果是数据ID用:
If IsInt(ID) then
'此处是正常ID的时间的查库代码
Else
'此处是不是数据,的报错代码
End If
如果是字符串你用:
str = ChecStr(Str) 就可以了,str是你要过滤的字串