ASP判斷E-Mail的合法性,以及過濾郵箱字元

來源:互聯網
上載者:User
'作者: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




相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。