Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

email input mask

Status
Not open for further replies.

psimon1

Technical User
Mar 18, 2003
55
US
Hello

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.

Thanks.
 
Hi!

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 (&quot;Email has an invalid format&quot;)
ElseIf (pos1 = &quot;@&quot;) Then
MsgBox (&quot;Email has an invalid format&quot;)
Else
tmp = InStr(2, email_2, &quot;@&quot;)
If (tmp = 0) Then
MsgBox (&quot;Email has an invalid format&quot;)
Else
tmp = tmp + 2
tmp2 = InStr(tmp, email_2, &quot;.&quot;)
If (tmp2 = 0) Then
MsgBox (&quot;Email has an invalid format&quot;)
Else
tmp2 = tmp2 + 1
tmp3 = Mid(email_2, tmp2, 1)
If (tmp3 <> &quot;&quot;) Then
checkEmail = True
Else
MsgBox (&quot;Email has an invalid format&quot;)
End If
End If
End If
End If

End Function


Code to access the above function

Private Sub checkEmail()
dim str as string

str = &quot;xxx@xx.xxx&quot;

if (checkEmail(str)) then
do something...
end if

End Sub


Have fun

M.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top