very basic email validation

Status
Not open for further replies.

ozinm

Human Coffee Siphon
Local time
Today, 02:39
Joined
Jul 10, 2003
Messages
121
someone could probably do a whole lot better but here goes:
Code:
Function ValidEmail(EMail As Variant) As Boolean
' Returns true if given a valid email address or Null
    'setup
    Dim TempCheck As Boolean
    Dim TempCount, TempLoop As Integer
    Dim TestData As Variant
    TempCheck = True
    TempCount = 0
    TempLoop = 0
    If Not IsNull(EMail) Then 'don't bother checking if email is empty
        'check of invalid characters
        For TempLoop = 1 To Len(EMail)
            Select Case Asc(Mid(EMail, TempLoop, 1))
                Case 0 To 45
                    TempCheck = False
                Case 47
                    TempCheck = False
                Case 58 To 63
                    TempCheck = False
                Case 91 To 94
                    TempCheck = False
                Case 96
                    TempCheck = False
                Case Is > 122
                Case Else
            End Select
        Next TempLoop
    
        'check for 1 "@" character only
        TempCount = 0
        TempLoop = 0
        Do
            TempLoop = InStr(TempLoop + 1, EMail, "@")
            If TempLoop > 0 Then
              TempCount = TempCount + 1
            End If
        Loop Until TempLoop = 0
        If TempCount > 1 Or TempCount < 1 Then TempCheck = False
    End If
    'return result
    ValidEmail = TempCheck
End Function
 
Status
Not open for further replies.

Users who are viewing this thread

Back
Top Bottom