Verify proper email address entry in text field

  • Thread starter Thread starter John Barnes
  • Start date Start date
J

John Barnes

How can I check for proper format (name@domain) of a
user's email address in a text field on a form?

Thanks!
 
John,

Here is a function I use. I don't suppose it is perfect, but I think it
will catch most invalid syntax entries ...

**********
Public Function EmailCheck(EmAdd As String) As Boolean
Dim Tester As Boolean
If Len(EmAdd) = 0 Then
Tester = False
Else
Tester = True
Tester = Tester And InStr(EmAdd, "@") > 0
Tester = Tester And InStr(EmAdd, ",") = 0
Tester = Tester And InStr(EmAdd, ";") = 0
Tester = Tester And InStr(EmAdd, " ") = 0
Tester = Tester And InStr(Mid(EmAdd, InStr(EmAdd, "@") + 1),
"@") = 0
Tester = Tester And InStr(Mid(EmAdd, InStr(EmAdd, "@") + 1),
".") > 0
Tester = Tester And Right(EmAdd, 1) <> "."
End If
EmailCheck = Tester
End Function
***********

Put this code in a standard module, and then on your form, on the After
Update event of your email address control, put something like this...
If Not IsNull(Me.YourEmailAddress) Then
If EmailCheck(Me.YourEmailAddress) = False Then
MsgBox "Email address not valid"
End If
End If
 
Another option is to open the table in design view, and add a Validation
Rule on the field (lower pane in table design).

Something like this:
Is Null Or ((Like "*?@?*.?*") And (Not Like "*[ ,;]*"))

List any characters that are not allowed (including the space) inside the
square brackets.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top