<%
'*************************************************************************************************
Rem 判断发言是否来自外部
'ChkPost=false 来自外部提交(非法)
'ChkPost=true 合法提交表单
'*************************************************************************************************
function ChkPost()
dim server_v1,server_v2
chkpost=false
server_v1=Cstr(Request.ServerVariables("HTTP_REFERER"))
server_v2=Cstr(Request.ServerVariables("SERVER_NAME"))
if mid(server_v1,8,len(server_v2))<>server_v2 then
chkpost=false
else
chkpost=true
end if
end function
'************************************************************************************************
'验证是否含有特殊字符
'IsValid=false 验证的参数中含有特殊字符
'************************************************************************************************
function IsValid(str)
IsValid = true
strSource ="▲,△,▼,▽,◆,◇,○,◎,●,◢,◣,◤,◥,★,☆,☉,♀,♂,〇,■,□,▁,▂,▃,▄,▅,▆,▇,█,▉,▊,▋,▌,▍,▎,▏,▓,▕,╬,「,」,『,』,【,】,〒,〓,〖,〗,╋,→,¤,¥,⊙,≡,≌,※,!,*,~,$,|,/,/,#"
strs=Split(strSource, ",")
for i=1 to UBound(strs)
if InStr(str,strs(i))>0 then
IsValid = false
exit for
else
IsValid = true
end if
next
end function
'**********************************************************************************************
'验证是否含有非字母和数字
'IsDomainStr=false 验定的参数中含有非数字和字母有字符
'**********************************************************************************************
function IsDomainStr(str)
IsDomainStr = true
str=LCase(str)
strSource ="0123456789abcdefghijklmnopqrstuvwxyz"
for i=1 to len(str)
if InStr(strSource,mid(str,i,1))<=0 then
IsDomainStr = false
exit for
else
IsDomainStr = true
end if
next
end function
'********************************************************************************************
'验证Email
' IsValidEmail=false 验证的参数不符合邮箱的格式
'********************************************************************************************
function IsValidEmail(email)
dim names, name, i, c
'Check for valid syntax in an email address.
IsValidEmail = true
names = Split(email, "@")
if UBound(names) <> 1 then
IsValidEmail = false
exit function
end if
for each name in names
if Len(name) <= 0 then
IsValidEmail = false
exit function
end if
for i = 1 to Len(name)
c = Lcase(Mid(name, i, 1))
if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 and not IsNumeric(c) then
IsValidEmail = false
exit function
end if
next
if Left(name, 1) = "." or Right(name, 1) = "." then
IsValidEmail = false
exit function
end if
next
if InStr(names(1), ".") <= 0 then
IsValidEmail = false
exit function
end if
i = Len(names(1)) - InStrRev(names(1), ".")
if i <> 2 and i <> 3 then
IsValidEmail = false
exit function
end if
if InStr(email, "..") > 0 then
IsValidEmail = false
end if
end function
'********************************************************************************************************
'验证是否含有危险字符的函数
'IsStr=false 验证的参数中含有危险字符,不能通过!
'********************************************************************************************************
function IsStr(str)
IsStr=true
dim badstr
badstr="exec master|exec sp_|openrowset|opendatasource|select |delete |update |insert |' or '|exec%20master|exec%20sp_|delete%20|update%20|insert%20|'%20or%20'|'|select%20"
badstrs=split(badstr,"|")
for i=0 to UBound(badstrs)
if Instr(str,badstrs(i))>0 then
IsStr=false
exit for
end if
next
end function
'*******************************************************************************************************
'函数名:gotTopic
'作 用:截字符串,汉字一个算两个字符,英文算一个字符
'参 数:str ----原字符串
' strlen ----截取长度
'返回值:截取后的字符串
'*******************************************************************************************************
function gotTopic(str,strlen)
if str="" then
gotTopic=""
exit function
end if
dim l,t,c, i
str=replace(replace(replace(replace(str," "," "),""",chr(34)),">",">"),"<","<")
l=len(str)
t=0
for i=1 to l
c=Abs(Asc(Mid(str,i,1)))
if c>127 then
t=t+2
else
t=t+1
end if
if t>=strlen then
gotTopic=left(str,i)
exit for
else
gotTopic=str
end if
next
gotTopic=replace(replace(replace(replace(gotTopic," "," "),chr(34),"""),">",">"),"<","<")
end function
'*******************************************************************************************************
'函数名:Getstrlen
'作 用:取得字符串的长度,汉字一个算两个字符,英文算一个字符
'参 数:str ----原字符串
'返回值:字符串长度,一个整数
'*******************************************************************************************************
function Getstrlen(str)
if str="" then
Getstrlen=0
exit function
end if
dim l,t,c, i
str=replace(replace(replace(replace(str," "," "),""",chr(34)),">",">"),"<","<")
l=len(str)
t=0
for i=1 to l
c=Abs(Asc(Mid(str,i,1)))
if c>127 then
t=t+2
else
t=t+1
end if
next
Getstrlen=t
end function
'================================================================
'函数名:strLength
'作 用:求字符串长度。汉字算两个字符,英文算一个字符。
'参 数:str ----要求长度的字符串
'返回值:字符串长度
'================================================================
function strLength(str)
ON ERROR RESUME NEXT
if str="" then
strLength=0
exit function
end if
dim WINNT_CHINESE
WINNT_CHINESE = (len("中国")=2)
if WINNT_CHINESE then
dim l,t,c
dim i
l=len(str)
t=l
for i=1 to l
c=asc(mid(str,i,1))
if c<0 then c=c+65536
if c>255 then
t=t+1
end if
next
strLength=t
else
strLength=len(str)
end if
if err.number<>0 then err.clear
end function
%>