473,406 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Data Mask for EMail Addressess

I thought this was an easy question, but I can't find an answer anywhere.

How do I set up a data mask in Access for email addresses?

There are two parts I can't figure: First how to set up part of a mask to accept unlimited characters. Second, what character to use that will accept any character EXCEPT a space.

Please help. Thanks.


Dante
Apr 1 '09 #1
7 7820
ChipR
1,287 Expert 1GB
I haven't found any way to do either of these things with an input mask. One alternative is to use the BeforeUpdate or AfterUpdate event of the text box to check the text entered and make sure it's valid.
Apr 1 '09 #2
ADezii
8,834 Expert 8TB
@dantebothermy
A single Line of Code in the KeyPress() Event of a Text Box on a Form should accomplish what you are looking for. Assuming a Text Box Name of txtEMailAddress, the following Code will allow an Unlimited Number of Characters up to the defined Field Size, but will NOT allow a Space:
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtEMailAddress_KeyPress(KeyAscii As Integer)
  2.   'Do not allow a Space!
  3.   If KeyAscii = 32 Then KeyAscii = 0
  4. End Sub
Apr 1 '09 #3
ChipR
1,287 Expert 1GB
Although this prevents users from typing spaces, they can still enter invalid information by ctrl+v pasting text with spaces.
Apr 1 '09 #4
missinglinq
3,532 Expert 2GB
Apart from not having a space, valid addresses also have to have a single ampersand (@) and a valid generic top-level domain on the end.

The first two items are easy to check, but the sticking point comes when trying to verify the last point, the valid host domain types, i.e. com, edu, org, etc. because the possibilities are almost endless, especially if you're dealing with government workers' addresses.

Here's a routine that checks for spaces, checks for a single ampersand and checks the most common generic top-level domains, such as .com, .org, .edu and .net., and throws up a messagebox if the address doesn't fall within these parameters.

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtEmailAddress_BeforeUpdate(Cancel As Integer)
  2.  
  3.  Dim DotEnding As String
  4.  Dim InputErr As Integer
  5.  
  6.  DotEnding = Right(txtEmailAddress, 4)
  7.  InputErr = 0
  8.  
  9.  If InStr(Me.txtEmailAddress, " ") > 0 Then
  10.   InputErr = InputErr + 1
  11.  End If
  12.  
  13. If Len(Me.txtEmailAddress) - Len(Replace(Me.txtEmailAddress, "@", "")) <> 1 Then
  14.   InputErr = InputErr + 1
  15.  End If
  16.  
  17. If DotEnding <> ".com" And DotEnding <> ".org" And DotEnding <> ".edu" And DotEnding <> ".net" Then
  18.   InputErr = InputErr + 1
  19. End If
  20.  
  21. If InputErr > 0 Then
  22.  MsgBox "You Have Entered An Invalid Email Address!"
  23.  Cancel = True
  24. End If
  25.  
  26. End Sub
You'll have to decide what additional top-level domains, if any, that you want to accept, and modify the code according, following the example in Lines 17-19 above.

Here's an article on Wikipedia listing some of the more common ones:

http://en.wikipedia.org/wiki/Generic_top-level_domain

This code will also notify the user if an invalid address is copied then pasted into the field.

Linq ;0)>
Apr 2 '09 #5
ADezii
8,834 Expert 8TB
You can actually list an endless number of Domains while still keeping the code compact and somewhat efficient:
  1. Create a Table named tblDomains
  2. Create a Field within this Table named [Domain] {TEXT 4}
  3. Enter all potential Domain Values within this Field: .com, .org, .edu. etc.
  4. Incorporate the following logic into linq's code:
    Expand|Select|Wrap|Line Numbers
    1. If DCount("*", "tblDomains", "[Domain] = '" & DotEnding & "'") = 0 Then
    2.   InputErr = InputErr + 1
    3. End If
Apr 2 '09 #6
missinglinq
3,532 Expert 2GB
Great enhancement, ADezii!

Linq ;0)>
Apr 2 '09 #7
ADezii
8,834 Expert 8TB
@missinglinq
Thank you linq, simply following in your footsteps!
Apr 2 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: dude | last post by:
hello how would i make an input mask that only makes the first letter a capitol one? i've been playing around and testing various masks, also tried the wizard, but i've had no luck. could...
2
by: Francis Debrabandere | last post by:
Hi all, I'm a beginner in ms access, and I'm working on my first real application. But to finish it up I'm facing a problem. I'm not able to solve and maybe someone can help me. I have made a...
11
by: MS | last post by:
The simplest input mask for peoples names is.... >L<?????????????? But what about when you have names like MacDonald, or Mary-Anne? Anyone come up with a good "all round" "idiots" mask that...
11
by: ex laguna | last post by:
How do I find the lowest bit position of a mask using only macros? I want to do everything in compile time. That mean, there cannot be control statements such as if, while, for, etc. in the...
1
by: Mike L | last post by:
How do I create a text box with date data mask? I also need a text box with SSN data mask. VB6 and Access was easy to use data mask, .Net makes some basic things hard to do.
15
by: Crirus | last post by:
I need to allow only numbers into a text box -- Cheers, Crirus ------------------------------ If work were a good thing, the boss would take it all from you ------------------------------
9
by: sellcraig | last post by:
Microsoft access 2 tables table "data main" contains a field called "code" table "ddw1" is created from a make table query of "data main" Goal- the data in "code" field in needs to...
8
by: jamesburkett | last post by:
I'm trying to clear text from a MaskEditBox control. I thought the format to delete it was: 'clear the mask mskName.Mask = "" 'clear the text mskName.Text = "" 'reassign the mask...
7
by: canajien | last post by:
How can I get a php page to automatically send all the contents in an email when it is generated? I managed to hack together a script that sends an email, but it will only send the 1st record...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.