判断是否为合法的电子邮件地址

来源:互联网 发布:战龙三国玉佩进阶数据 编辑:程序博客网 时间:2024/05/09 05:32
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'判断是否为合法的电子邮件地址 True 合法 False 非法
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function IsValidEmail(Email)
 Dim Names, name, i, c
 IsValidEmail = True
 Names = Split(Email, "@")
 
 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(Email, "..") > 0 Then
  IsValidEmail = False
 End If
End function 
原创粉丝点击