by Chris Morton (5 Submissions)
Category: String Manipulation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 30th September 2005
Date Added: Mon 8th February 2021
Rating: (1 Votes)
validate email string with function returns boolean
Dim i As Integer
Dim atplace As Integer
Dim dotplace 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
dotplace = i
End If
If InStr("[email protected]_", LCase(Mid(Email, i, 1))) > 0 Then 'checks for illegal charaters
Else
Return False
Exit Function
End If
Next
If dotplace < atplace Or Len(Email) = dotplace Then 'checks to see whether the is a . after the @ and if something follows after the .
Return False
Exit Function
End If
If atcount <> 1 Then 'checks if there are invalid or no @ symbols
atcountboo = False
Else
atcountboo = True
End If
If Mid(Email, 1, 1) = "@" Or Mid(Email, Len(Email), 1) = "@" Then 'checks if the first or last 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