打印本文 打印本文 关闭窗口 关闭窗口
判断字符串是否是合法的EMail
作者:武汉SEO闵涛  文章来源:敏韬网  点击数667  更新时间:2009/4/23 18:59:39  文章录入:mintao  责任编辑:mintao

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

打印本文 打印本文 关闭窗口 关闭窗口