[mso] Re: Question about E-Mail Input Mask

  • From: "Jim Pettit" <jimpettit@xxxxxxxxx>
  • To: <mso@xxxxxxxxxxxxx>
  • Date: Mon, 2 May 2005 12:56:07 -0700

Scot--

I've found that using what are called 'Regular Expressions' work very well
for validation, and while scary to look at, they run fast, and are pretty
small. Here's my 'standard' email checker:

1) In a standard module, cut and paste the following:

Private re As Object

Public Function isEmailValid(sEMail As String) As Boolean
    If (re Is Nothing) Then
        Set re = CreateObject("vbscript.regexp")
    End If
    re.Pattern = "^(([a-zA-Z0-9]+_+)|([a-zA-Z0-9]+\-+)|" & _
        "([a-zA-Z0-9]+\.+)|([a-zA-Z0-9]+\++))*" & _
        "[a-zA-Z0-9]+@((\w+\+)|(\w+\.))*\w{1,63}" & _
        "\.[a-zA-Z0-9]{2,6}$"
    isEmailValid = re.test(sEMail)
End Function

(Note that the line 'Private re As Object' is NOT in a procedure, but rather
in the declaration section of the module.)

2) If you want to check the addresses as they're being entered into a form,
just place the following into the email address field's After Update event
handler:

Private Sub txtEmail_AfterUpdate()
    If isEmailValid(txtEmail) Then
        MsgBox "Good Address"
    Else
        MsgBox "Bad address!"
        DoCmd.RunCommand acCmdUndo
        ' Do whatever...        
    End If
End Sub

3) If, on the other hand, you want to check all the existing address to see
which ones are 'bad', enter the following into a new query:

SELECT IIf(isEmailValid([sEmailField]),"GOOD","BAD") AS FROM tblPeople

Of course, these are flimsy examples that'll need to be fleshed out to
really work. But you get the idea...I hope. ;-)

--Jim 

-----Original Message-----
From: mso-bounce@xxxxxxxxxxxxx [mailto:mso-bounce@xxxxxxxxxxxxx] On Behalf
Of Scot Jones
Sent: Monday, May 02, 2005 12:22 PM
To: mso@xxxxxxxxxxxxx
Subject: [mso] Question about E-Mail Input Mask


Okay, so I have just decided to learn Access in response to being told by my
company that I needed to assemble a database that will track the training
records of several thousand people.  I am definitely a newbie - 

I am trying to figure out how to create an input mask within a table that
will force the result to include XXXX@xxxxxxxx (and the first 2 sets of Xs
should allow almost unlimited number of characters, while the last three
should always be 3).  

Am I way off in the wrong direction by thinking input mask, or does anyone
know how I would do this?

Thanks!

Scot Jones

*************************************************************
You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or
MicrosoftOffice@xxxxxxxxxxxxxxxx

To send mail to the group, simply address it to mso@xxxxxxxxxxxxx

To Unsubscribe from this group, send an email to mso-request@xxxxxxxxxxxxx
with the word "unsubscribe" (without the quotes) in the subject line.

Or, visit the group's homepage and use the dropdown menu.  This will also
allow you to change your email settings to digest or vacation (no mail).
//www.freelists.org/webpage/mso

To be able to use the files section for sharing files with the group, send a
request to mso-moderators@xxxxxxxxxxxxx and you will be sent an invitation
with instructions.  Once you are a member of the files group, you can go
here to upload/download files:
http://www.smartgroups.com/vault/msofiles
*************************************************************

*************************************************************
You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or 
MicrosoftOffice@xxxxxxxxxxxxxxxx

To send mail to the group, simply address it to mso@xxxxxxxxxxxxx

To Unsubscribe from this group, send an email to 
mso-request@xxxxxxxxxxxxx with the word "unsubscribe" (without the quotes) in 
the subject line.

Or, visit the group's homepage and use the dropdown menu.  This will also allow 
you to change your email settings to digest or vacation (no mail).
//www.freelists.org/webpage/mso

To be able to use the files section for sharing files with the group, send a 
request to mso-moderators@xxxxxxxxxxxxx and you will be sent an invitation with 
instructions.  Once you are a member of the files group, you can go here to 
upload/download files:
http://www.smartgroups.com/vault/msofiles
*************************************************************

Other related posts: