email field validation

ianatkins

Registered User.
Local time
Today, 12:51
Joined
Oct 25, 2002
Messages
16
Hi,
Ive been trying to find out a method to validate an email field. I basically want something to check whether there is a . and an @ in the field.

Can this be done at table level or shall I do it on the form , and how can I do it!!

Thanks alot,
ian.
 
You have to do it in a form. This is a bit crude, but should work:

Dim counter, x As Integer
counter = 0

For x = 1 To Len(Text0)
If Mid(Text0, x, 1) = "." Or Mid(Text0, x, 1) = "@" Or Then
counter = counter + 1
End If
Next x

If counter <> 2 Then
MsgBox "Email is missing the period or the At sign"
End If

Replace Text0 with the name of the control with the email address.

hth,
Jack
 
Jack's idea won't trap an address with two "@" or one with two "." and no "@". Try two counters, one for "@" which must count to 1 and one for "." which must count to more than 0

Outside the US, many email addresses and URLs have two "." chars. Since people ofter enter a URL when they are asked for an e-mail, you need to check for on and only one "@" and one or more "."

As Jack suggests, this is still not full validation but it's a good start.

If you want to go further, you could check that neither the first nor the last char is a "@" or a "."
 
Hmmm. Just saw an error in my code that I missed when I wrote it. This is correct:

Dim counter, x As Integer
counter = 0

For x = 1 To Len(Text0)
If Mid(Text0, x, 1) = "." Or Mid(Text0, x, 1) = "@" Then
counter = counter + 1
End If
Next x

If counter <> 2 Then
MsgBox "Email is missing the period or the At sign"
End If

Jack
 

Users who are viewing this thread

Back
Top Bottom