E-mail Input Mask

Dragonzstealth

New Member
Joined
Jan 27, 2006
Messages
13
Hi guys, just wondering if anyone out there in internet land knows an input mask for e-mail addresses. I'm apparently too dumb to figure this one out on my own. Thanks.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
I don't think you will find an input mask, but what I would think would help would be something to check the email address during the BeforeUpdate event.
I would think that this routine would check for blanks (should be none), make sure there is only one "at" sign (@), and then something that looks like a valid domain address which would be xxxxx.xxxx or xxxxx.xxxxx.xx.xxxx. In other words, at least one period (.).
Someone might even have this already coded and could share it with you.
 
Upvote 0
Hi

As you may be aware, input masks are used to control the way data is captured but they don't naturally lend themselves to text fields of variable length. If you are using a form to enter the e-mail addresses, you can use a 'before update' event to ensure the address conforms to your expectations. Or you could use a validation rule (at the table level) like this:

Like "*" & "@" & "*" & "." & "*"

With this validation rule the user has to input the ampersand and decimal point.

HTH, Andrew
 
Upvote 0
Hi Andrew, just a quickie question:
Does
Code:
Like "*" & "@" & "*" & "." & "*"
function any differently from
Code:
Like "*@*.*"
?
 
Upvote 0
Hi

Apprently not. Well spotted. Keep in mind both have errors in that you can enter just @. and it will accept it (or something like 1@.). I think my format was a carry-over from a failed attempt at an input mask. The more correct way would be to use a VBA solution.

Andrew
 
Upvote 0
I truthfully wasn't sure. Good point on the holes though. I am building a new d-base anyhow, (hence me searching out this thread) :biggrin: so I had to invest some time in this task one way or the other. So here is what I have whipped up so far (greatly modified thanks to your point about the problems with *@*.*).
For the "@." problem you can force any number of characters you want in between literals with "?". So I use the ?*@?*.?* mask to get a good general overall pattern:
Code:
[MyField]) like "?*@?*.?*"
Force a minimum length of 5 (your 2 literals and 3 fillers) and all lowercase using input mask:
(My field is 50 characters.)
Code:
<&&&&&CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
I also put in lenth restrictions on the validation rule should the input mask not make it to the form for some reason.
Code:
LenB([MyField])>8 and lenB([MyField]) < 102
Use the COUNTIN formula provided by pgc01 (http://www.mrexcel.com/board2/viewtopic.php?t=234046) to unsure only 1 occurance of "@".
Code:
(LenB([MyField]) - LenB(Replace([MyField], "@", ""))) / LenB("@")=1
I am still working on a ways to eliminate forbidden characters.

But for now the combined validation is this:
Code:
[MyField] like "?*@?*.?*" and LenB([MyField])>8 and lenB([MyField]) < 102 and (LenB([MyField]) - LenB(Replace([MyField], "@", ""))) / LenB("@")=1
 
Upvote 0
you could also use the split function to get a count of @'s:
Code:
Sub SplitTest()
       Debug.Print UBound(Split("giacomo.spam@gmail.com", "@"))
       Debug.Print UBound(Split("giacomo@spam@gmail.com", "@"))
       Debug.Print UBound(Split("giacomo.spam@@gmail.com", "@"))
       Debug.Print UBound(Split("giacomo.spam.gmail.com", "@"))
End Sub

hth,
Giacomo
 
Upvote 0
That is pretty nifty except you can't use UDFs or the UBound/Split commands in table level validation. (I think you might be able to if you turn off sandboxmode, but I don't want to do that.)
 
Upvote 0
That is pretty nifty except you can't use UDFs or the UBound/Split commands in table level validation. (I think you might be able to if you turn off sandboxmode, but I don't want to do that.)

OK, you win on the ubound/split but you can totally use UDF's. I used j-walk's CountOccurrences function as a test and it worked fine.

Rich (BB code):
Function CountOccurrences(str, substring) As Long
'   Returns the number of times substring appears in str
    Dim x As Variant
    x = Split(str, substring)
    CountOccurrences = UBound(x)
End Function

Rich (BB code):
SELECT CountOccurrences([email_addr],"@") AS AtCount
FROM someTable;

hth,
Giacomo
 
Upvote 0

Forum statistics

Threads
1,215,877
Messages
6,127,494
Members
449,385
Latest member
KMGLarson

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top