I was playing around with email input masks on forms and tables. Anyone have a template? I would like to ensure that there's xxx@xxx.com, with the '@' and '.com' fields required, as well as at least two strings in the name and domain fields.
Here is a function that I wrote myself to check for a valid email. Although it is not complete but it checks for the most common things such as:
-correct length
-contains '@'
-position of the '@'
-contains a '.' after the '@'
-contains atleast two characters after the '@' and the '.'
The function takes an email as a parameter and returns true or false
Public Function checkEmail(e As String) As Boolean
Dim email_2 As String
Dim pos1 As String
Dim tmp As Variant
Dim tmp2 As Variant
Dim tmp3 As Variant
Dim str As Integer
email_2 = e
pos1 = Mid(email_2, 1, 1)
If (Len(email_2) < 6) Then
MsgBox ("Email has an invalid format"
ElseIf (pos1 = "@" Then
MsgBox ("Email has an invalid format"
Else
tmp = InStr(2, email_2, "@"
If (tmp = 0) Then
MsgBox ("Email has an invalid format"
Else
tmp = tmp + 2
tmp2 = InStr(tmp, email_2, "."
If (tmp2 = 0) Then
MsgBox ("Email has an invalid format"
Else
tmp2 = tmp2 + 1
tmp3 = Mid(email_2, tmp2, 1)
If (tmp3 <> "" Then
checkEmail = True
Else
MsgBox ("Email has an invalid format"
End If
End If
End If
End If
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.