View Full Version : Validation rule for an email


Matizo
01-31-2007, 02:30 PM
Hello,
I was looking for the validation rule or input mask for an email but I could not find anything what would match what I need.

Any ideas how can I validate an email or use an input mask for it?

Thanks,
Matt

Moniker
01-31-2007, 03:26 PM
In the BeforeUpdate event of the email field, put this:

If InStr(1,[Email_Field_Name],"@")=0 Or InStr(1,[Email_Field_Name],".")=0 Then
MsgBox "Please enter an email in the name@domain.com format."
Cancel = True
End If

That will check for the @ symbol and a dot (as in .com, .org, etc.) and if either is missing, it will tell the user the email format is wrong and keep the focus on the email field.

pbaldy
01-31-2007, 03:36 PM
I don't know of any validation rule or input mask that could work. I check it after it's entered. There's a good one here:

http://www.access-programmers.co.uk/forums/showthread.php?t=79343

I've also used a regexp on a website, which seems to work pretty well.

Matizo
01-31-2007, 03:38 PM
I created a macro to run this code:

If InStr(1,[email],"@")=0 Or InStr(1,[email],".")=0 Then
MsgBox "Please enter an email in the name@domain.com format."
Cancel = True
End If

and then set the macro in the BeforeUpdate event. But it did not work:confused:

Is there anything that I could set in the table? Under the Validation rule section?

Thanks,

Moniker
01-31-2007, 03:41 PM
There's no validation rule or format I'm aware of. Why are you using a macro? What was wrong with the code I provided or the more detailed example that pbaldy linked to?

Matizo
01-31-2007, 03:46 PM
By using a macro I tried to make it simpler, I am doing a project for A2 Level and I’m afraid I would not be able to describe fully the code you gave me in the implementation section:eek: