'----------------------------------------------------------------------------------- '--FUNCTION : EmailCheck '--INPUT : str as string '--OUTPUT : EmailCheck as boolean '--DESCRIPTION : check the email's format '------------------------------------------------------------------------------------- Public Function EmailCheck(strEmail As String) As Boolean On Error GoTo ToExit 'OPEN ERROR PORT '------------------------------------------------
Dim names, name, i, c Dim IsValidEmail As Boolean 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 EmailCheck = IsValidEmail '------------------------------------------------ Exit Function '---------------- ToExit: End Function
'--FUNCTION : EmailCheck
'--INPUT : str as string
'--OUTPUT : EmailCheck as boolean
'--DESCRIPTION : check the email's format
'-------------------------------------------------------------------------------------
Public Function EmailCheck(strEmail As String) As Boolean
On Error GoTo ToExit 'OPEN ERROR PORT
'------------------------------------------------
Dim names, name, i, c
Dim IsValidEmail As Boolean
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
EmailCheck = IsValidEmail
'------------------------------------------------
Exit Function
'----------------
ToExit:
End Function