Author : Chris Morton
Date Submitted : 9/30/2005
Category : Other
Compatibility : VB 6
This code has been accessed 3063 times.
Task : Validates Email Address
Declarations
Code
Private Function ValidateEmail(ByVal Email As String) As Boolean
Dim i As Integer
Dim atplace As Integer
Dim atcount As Integer
Dim atcountboo As Boolean
Dim dotcount As Integer
For i = 1 To Len(Email)
If Mid(Email, i, 1) = "@" Then 'Checks where the location of the @ symbol is and if there is more than 1
atcount = atcount + 1
atplace = i
End If
If Mid(Email, i, 1) = "." Then
dotcount = dotcount + 1
End If
If Mid(Email, i, 1) = "!" Or Mid(Email, i, 1) = "#" Then 'checks for illegal characters
Return False
Exit Function
End If
Next
If atcount <> 1 Then 'checks if there are invalid or no @ symbols
atcountboo = False
Else
atcountboo = True
End If
If Mid(Email, 1, 1) = "@" Then 'checks if the first charater is @
Return False
End If
If Mid(Email, atplace + 1, 1) = "." Then 'checks if the character after @ is a .
Return False
End If
If dotcount >= 1 And atcountboo = True Then 'checks if there is at least 1 . and an @ exists in the right place
Return True
Else
Return False
End If
End Function