regular expression for email with one domain

L

ll

I am trying to finalize a regular expression in javascript to only
allow emails with a certain domain to be valid.

Here is what I have so far:

var emailFilter2=/[^\w\-\.]\@aol.com/;
if(!(emailFilter2.test(strng))) {
error = "Please enter a valid email address with the AOL domain.\n
\n";
}


Thanks for any help with this.
Louis
 
E

Elegie

ll wrote:

Hi,
I am trying to finalize a regular expression in javascript to only
allow emails with a certain domain to be valid.

Unfortunately, email addresses cannot (probably) be tested with one
single regexp, given the syntax options available in the relevant RFC.
Moreover, a valid address, i.e. respecting the format defined in the
specification, may simply not be receiving mail (it could be some fake
address).

Please check the following page, Appendix, Part 5, "Verifying Email
Addresses", by Elijah Pogonatus. Also, pay attention to the two examples
provided by the author.

<URL:http://www.faqs.org/faqs/mail/addressing/>

The thing is, it might simply be better to rethink your approach. If you
accept only AOL email addresses, then why not use something like (along
with some confirmation link sent to the address):
 
E

Evertjan.

ll wrote on 13 feb 2007 in comp.lang.javascript:
I am trying to finalize a regular expression in javascript to only
allow emails with a certain domain to be valid.

Here is what I have so far:

var emailFilter2=/[^\w\-\.]\@aol.com/;

The . after aol should be escaped.
You should allow for case insensitivity.
You should test for the end of string with $.
if(!(emailFilter2.test(strng))) {
error = "Please enter a valid email address with the AOL
domain.\n
\n";
}


Far simpler, if you are only interested in testing the domain part:

if (/.@aol\.com$/i.test(strng))
.....

If you want to test the part bedore the @,
the problem is far greater.

You would have to start with knowing the axact definition.
 
L

ll

Far simpler, if you are only interested in testing the domain part:
if (/.@aol\.com$/i.test(strng))
.....

Thanks for your reply,
If I wanted to compare for two domains, would there be a way? I've
tried this (below) but it fails to trap other domains?
Thanks again
Louis

//
if (!(/.@aol\.com$/i.test(strng))) || if (!(/.@yahoo\.com$/
i.test(strng)))
{
error="Please enter a valid email address with either aol or yahoo
domain.\n\n";
}
 
E

Evertjan.

ll wrote on 14 feb 2007 in comp.lang.javascript:
Thanks for your reply,
If I wanted to compare for two domains, would there be a way? I've
tried this (below) but it fails to trap other domains?

//
if (!(/.@aol\.com$/i.test(strng))) || if (!(/.@yahoo\.com$/

No you cannot "or" two if-s because they are statements.

[read up on both javascript and regular expressions please]

if (/.@(aol|yahoo)\.com$/i.test(emailStr))
alert('One of those found!')
 
E

Evertjan.

Michael White wrote on 14 feb 2007 in comp.lang.javascript:
if (/.@(aol)|(yahoo)\.com$/i.test(emailStr))

Aren't the parentheses needed to prevent matching
"aolahoo" and "aoyahoo" ?

did you test this?
 
D

Dr J R Stockton

In comp.lang.javascript message said:
ll wrote:

Try OK = /@some\.domain\.name$/.test(Str)
Unfortunately, email addresses cannot (probably) be tested with one
single regexp, given the syntax options available in the relevant RFC.

That was not the question.
Moreover, a valid address, i.e. respecting the format defined in the
specification, may simply not be receiving mail (it could be some fake
address).

Neither was that.

Whatever the OP may have meant, the question requires that all mail not
addressed to a specific domain be disallowed.

All mail addressed to the domain which I am now using will have "merlyn"
in the address; but so will mail to Joe.merlyn (*at) elsewhere.kom.

Mail addressed to the domain will necessarily have a particular right
part.

One might attempt to address mail to the dotted quad - would that count
as the domain?

Mail addressed to my name in another domain will be redirected to my
domain; the OP could allow mail to that other domain, but it redirects
in many directions.
 
E

Elegie

Dr J R Stockton wrote:

Hi John,

That was not the question.

Neither was that.

Yes, the information I have provided did not answer to the exact
question. However, I had the feeling that this original question had
some issues itself, and that explaining these could help the OP into
getting a better overview of his process. Still, offering a caveat
without providing the straight answer was, as you suggested, probably
some mistake from my side.

Collecting email addresses generally exposes some will to use them in
the future. A valid email address should not only respect a certain
format, but should also reach its recipient. Unfortunately, most people
tend to believe that testing for some particular format suffices (and to
me the OQ was a potential expression of this syndrome), potentially
building critical processes on unchecked data.

Also, when designing an application, one should nearly never request the
user to enter some input that is already predefined. Doing so can only
confuse the user and slow down his inputting data.
Whatever the OP may have meant, the question requires that all mail not
addressed to a specific domain be disallowed.

Which is why I proposed an alternate approach, not using a regular
expression, but rather forcing the domain as plain text and simply
requesting the local part of the address...
All mail addressed to the domain which I am now using will have "merlyn"
in the address; but so will mail to Joe.merlyn (*at) elsewhere.kom.

Mail addressed to the domain will necessarily have a particular right
part.

That is true, and most of the time people providing their email address
would not complicate it using inappropriate subtleties, which should
eventually make this 'right part' not too complicated to spot - though
in regards of the possibilities permitted by the RFC, a regular
expression alone is probably not enough to spot it safely.
One might attempt to address mail to the dotted quad - would that count
as the domain?

If by "dotted quad" you refer to the IP address, then yes, that would
indeed count as the domain.
Mail addressed to my name in another domain will be redirected to my
domain; the OP could allow mail to that other domain, but it redirects
in many directions.

Quite an interesting point, but if some non AOL address redirects to the
AOL one, then why not supply the AOL one in the first place? What if the
user eventually switches email? Would this make him/her still a target?
To which extent is the email a relevant criteria?


Kind regards,
Elegie.
 
D

Dr J R Stockton

In comp.lang.javascript message said:
Quite an interesting point, but if some non AOL address redirects to
the AOL one, then why not supply the AOL one in the first place? What
if the user eventually switches email? Would this make him/her still a
target? To which extent is the email a relevant criteria?

With my present setup, I only collect mail from Demon, and it is only my
Demon address that I expose in News headers.

I give my redirecting address only to trusted people who might want to
use it after I have abandoned the Demon mail address, before which I
shall re-aim the redirector. Then I will be receiving at a different
domain, though the redirected mail will be sent as before to the
redirecting domain.

At one time, IIRC, a lower-grade professional organisation gave me
redirection facilities, which I did not need or choose to use; I could
have used it to redirect either to the Demon address or to the other
redirector. They withdrew the facility when I pointed out that I was
not a member.

It is for such reasons that it is necessary for the original question to
be asked with great care. Likewise, those who reply should be careful
to indicate where they are answering the original question, and where
they are providing other related advice.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top