判断字符串是否是合法的EMail

文章作者 100test 发表时间 2007:12:05 12:11:13
来源 100Test.Com百考试题网


Public Function IsValidEmail(strEmail As String) As Boolean
Dim names, name, i, c
IsValidEmail = True

names = Split(strEmail, "@")

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
Exit Function
End If

i = Len(names(1)) - InStrRev(names(1), ".")

If i <> 2 And i <> 3 Then
IsValidEmail = False
Exit Function
End If

If InStr(strEmail, "..") > 0 Then
IsValidEmail = False
Exit Function
End If

End Function



相关文章


判断字符串是否是合法的EMail
VB6如何在托盘中写入应用程序图标
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛