ASP判断E-Mail的合法性,以及过滤邮箱字符

80酷酷网    80kuku.com

  '作者: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


分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: