'作者:Loster(OICQ:181306) [如果轉載請勿刪除此資訊,謝謝!]
'函數名:chk_Email()
'傳回值:布爾值(True為通過,False為未通過)
'參數:email(需要判斷的email,類型:字串) Type_1(是否需要判斷@之後的domain,類型:布爾值)
'Type_2(是否只能是特定域的E-Mail註冊,類型:布爾值) Type_3(一個E-Mail是否只能註冊一次,類型:布爾值)
Const C_maildomain=".com,.com.cn,.net,.net.cn,.org,.org.cn,.gov,.gov.cn,.edu,.edu.cn,.cn,.cc,.biz,.info" '電子郵件可接受的domain
Const C_Lockdomain="bit.edu.cn,loster.org" '特定的域
Function chk_Email(email,Type_1,Type_2,Type_3)
Dim i,k
Dim At
Dim Email_1,Temp
If email="" Then
chk_Email=False
Exit Function
End If
Email_1=Cstr(trim(email))
If Len(Email_1)<5 Then
chk_Email=False
Exit Function
End If
At=False
For i=1 To Len(Email_1)
Temp=Mid(Email_1,i,1)
If Temp="@" Then
at=True
Exit For
End If
Next
If At=False Then
Chk_Email=False
Exit Function
End If
k=0
For i=1 To Len(Email_1)
Temp=Mid(Email_1,i,1)
If Temp="." then
k=k+1
End If
Next
If k=0 Or k>2 Then
Chk_Email=False
Exit Function
End If
If Type_1=True Then
For i=1 To Len(Email_1)
Temp=Mid(Email_1,i,1)
If Temp="@" Then
k=i
Exit For
End If
Next
For i=k To Len(Email_1)
Temp=Mid(Email_1,i,1)
If Temp="." Then
k=i
Exit For
End If
Next
Temp=""
For i=k To Len(Email_1)
Temp=Temp+Mid(Email_1,i,1)
Next
Temp=Cstr(Trim(Temp))
At=False
For i=0 To R_Reader(C_Maildomain,",")
If Temp=Reader(i) Then
At=True
Exit For
End If
Next
Erase Reader
If At=False Then
Chk_Email=False
Exit Function
End If
End If
If Type_2=True Then
For i=1 To Len(Email_1)
Temp=Mid(Email_1,i,1)
If Temp="@" Then
k=i
Exit For
End If
Next
Temp=""
For i=k+1 To Len(Email_1)
Temp=Temp+Mid(Email_1,i,1)
Next
Temp=Cstr(Trim(Temp))
At=False
For i=0 To R_Reader(C_Lockdomain,",")
If Temp=Reader(i) Then
At=True
Exit For
End If
Next
Erase Reader
If At=False Then
Chk_Email=False
Exit Function
End If
End If
If Type_3=True Then
Dim j
Call Greate_UserDb()
Call Create_Rs("Select * from User_Basic_Info where User_Email='"&Email_1&"'",1,1,"User")
If Rs.Bof=False Then
Chk_email=False
Call Close_Rs()
Call Close_UserDb()
Exit Function
End If
Call Close_Rs()
Call Close_UserDb()
End If
chk_email=True
End Function
Dim User_Db,User_Driver
Dim User_Conn
User_Db="Data/userdata.mdb"
'建立User_conn的過程
Sub Greate_UserDb()
User_Driver="driver={Microsoft Access Driver (*.mdb)}"
User_Driver=User_Driver&";dbq="&server.mappath(User_Db)
'Response.Write (User_Driver)
Set User_Conn = Server.CreateObject("ADODB.Connection")
User_Conn.Open(User_Driver)
End Sub
'關閉User_conn的過程
Sub Close_UserDb()
User_Conn.Close
Set User_Conn=Nothing
End Sub
Dim Reader
Dim Rs
'讀取常數,並將每個常數儲存在reader數組中,參數:R_Str(常數串),F_Str(分隔字元),傳回值:Reader數組的下標
Function R_Reader(R_Str,F_Str)
Dim i
If R_Str="" Or F_Str="" Then
Exit Function
End If
Reader=Split(R_Str,F_Str)
For i=0 To Ubound(Reader,1)
Reader(i)=Cstr(Trim(Reader(i)))
Next
R_Reader=Ubound(Reader,1)
End Function