• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

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

发布: 2007-5-25 09:19 | 作者: jennyvenus | 来源: 互联网 | 查看: 40次 | 进入软件测试论坛讨论

领测软件测试网

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

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/