特别声明,以下有一些函数是从各个站点代码中截取,不完全是本人写的。如有异议,请与本人联系。
(9)检测Email地址是否合法
'********************************************
'函数名:IsValidEmail
'作 用:检查Email地址合法性
'参 数:email ----要检查的Email地址
'返回值:True ----Email地址合法
' False ----Email地址不合法
function IsValidEmail(email)
dim names, name, i, c
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
i = Len(names(1)) - InStrRev(names(1), ".")
if i <> 2 and i <> 3 then
if InStr(email, "..") > 0 then
end function
(10)检测上页是否从本站提交
' ============================================
' 检测上页是否从本站提交
' 返回:True,False
Function IsSelfRefer()
Dim sHttp_Referer, sServer_Name
sHttp_Referer = CStr(Request.ServerVariables("HTTP_REFERER"))
sServer_Name = CStr(Request.ServerVariables("SERVER_NAME"))
If Mid(sHttp_Referer, 8, Len(sServer_Name)) = sServer_Name Then
IsSelfRefer = True
Else
IsSelfRefer = False
End If
End Function
(11)得到安全字符串,在查询中使用
' 得到安全字符串,在查询中使用
Function Get_SafeStr(str)
Get_SafeStr = Replace(Replace(Replace(Trim(str), "'", ""), Chr(34), ""), ";", "")
(11)取实际字符长度
' 取实际字符长度
Function Get_TrueLen(str)
Dim l, t, c, 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
Next
Get_TrueLen = t
End Fu
nction
(12)判断是否安全字符串,在注册登录等特殊字段中使用
' 判断是否安全字符串,在注册登录等特殊字段中使用
Function IsSafeStr(str)
Dim s_BadStr, n, i
s_BadStr = "' &<>?%,;:()`~!@#$^*{}[]|+-=" & Chr(34) & Chr(9) & Chr(32)
n = Len(s_BadStr)
IsSafeStr = True
For i = 1 To n
If Instr(str, Mid(s_BadStr, i, 1)) > 0 Then
IsSafeStr = False
Exit Function
End If
(14)格式化时间(显示)
' 格式化时间(显示)
' 参数:n_Flag
' 1:"yyyy-mm-dd hh:mm:ss"
' 2:"yyyy-mm-dd"
' 3:"hh:mm:ss"
' 4:"yyyy年mm月dd日"
' 5:"yyyymmdd"
Function Format_Time(s_Time, n_Flag)
Dim y, m, d, h, mi, s
Format_Time = ""
If IsDate(s_Time) = False Then Exit Function
y = cstr(year(s_Time))
m = cstr(month(s_Time))
If len(m) = 1 Then m = "0" & m
d = cstr(day(s_Time))
If len(d) = 1 Then d = "0" & d
h = cstr(hour(s_Time))
If len(h) = 1 Then h = "0" & h
mi = cstr(minute(s_Time))
If len(mi) = 1 Then mi = "0" & mi
s = cstr(second(s_Time))
If len(s) = 1 Then s = "0" & s
Select Case n_Flag
Case 1
' yyyy-mm-dd hh:mm:ss
Format_Time = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s
Case 2
' yyyy-mm-dd
Format_Time = y & "-" & m & "-" & d
Case 3
' hh:mm:ss
Format_Time = h & ":" & mi & ":" & s
Case 4
' yyyy年mm月dd日
Format_Time = y & "年" & m & "月" & d & "日"
Case 5
' yyyymmdd
Format_Time = y & m & d
End Select
(15)格式化性别显示
'sex字段必须是数字
Function Format_sex(sex)
select case sex
case 1
Format_sex="女"
case 0
Format_sex= "男"
(16)格式化血型函数
'*********显示血型函数*********
Function Format_bloodType(bloodType)
select case bloodType
case 1
Format_bloodType= "A型"
case 2
Format_bloodType="B型"
case 3
Format_bloodType="AB型"
case 4
Format_bloodType="O型"
case 5
Format_bloodType="不清楚"
'*********显示结婚状态函数*********
Function Format_marry(marry)
select case marry
Format_marry= "未婚"
case 1
Format_marry="离异"
case 2
Format_marry="丧偶"
'************格式化收入显示函数********************
Function Format_income(income)
select case income
Format_income="1000以下"
Format_income="1000~2000"
Format_income="2000~3000"
case 3
Format_income="3000~4000"
case 4
Format_income="4000~5000"
Format_income="5000~6000"
case 6
Format_income="6000~8000"
case 8
Format_income="8000~12000"
case 12
Format_income="12000~20000"
case 20
Format_income="20000以上"
'****************显示学历函数**************
Function Format_edu(edu)
select case edu
Format_edu= "大专以下"
Format_edu="本科"
Format_edu="硕士"
case 4
Format_edu= "博士"
case 5
Format_edu="博士后"
'****************显示年龄函数**************
Function Format_age(age)
select case age
Format_age= year(now)-year(age)
本文转自 simeon2005 51CTO博客,原文链接:http://blog.51cto.com/simeon/9665