上篇文章我們用字串尋找的方法實現了asp email郵箱地址的驗證,有可能比較喜歡Regex的朋友,這裡也給出相應的代碼。
方法一
複製代碼 代碼如下:Public Function ChkMail(ByVal Email)
Dim Rep,Pmail : ChkMail = True : Set Rep = New RegExp
Rep.Pattern = "([.a-zA-Z0-9_-]){2,10}@([a-zA-Z0-9_-]){2,10}(.([a-zA-Z0-9]){2,}){1,4}$"
Pmail = Rep.Test(Email) : Set Rep = Nothing
If Not Pmail Then ChkMail = False
End Function
郵箱地址驗證二 複製代碼 代碼如下:<%
Function isemail(strng)
isemail = false
Dim regEx, Match
Set regEx = New RegExp
regEx.Pattern = "^w+((-w+)|(.w+))*@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+)*.[A-Za-z0-9]+$"
regEx.IgnoreCase = True
Set Match = regEx.Execute(strng)
if match.count then isemail= true
End Function
%>
方法三 複製代碼 代碼如下:Public Function IsEmail(ByVal PString)
Dim Plt,Pgt : Plt = False : Pgt = False
For x = 2 To Len(PString) - 1
If Mid(PString,x,1) = "@" Then Plt = True
If Mid(PString,x,1) = "." And Plt = True Then Pgt = True
Next
If Plt = True And Pgt = True Then
IsEmail = True
Else
IsEmail = False
End if
End Function
%>
我們來看看驗證一的執行個體使用方法 複製代碼 代碼如下:If ChkMail(admin@jb51.net) = True Then
Response.Write "格式正確"
Else
Response.Write "格式有誤"
End If