Need REGEX pattern matching help

P

pbd22

i have the pattern that checks for bad email:

var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-
Z])+/;

I want to add a check for a domain name: "mycompany"
such that:

(e-mail address removed)

is a match. and, any other domain is not a match.

Any gurus know how to add this piece?

Thanks.
Peter
 
E

Evertjan.

pbd22 wrote on 20 feb 2008 in comp.lang.javascript:
i have the pattern that checks for bad email:

var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-
Z])+/;

No, it can check for a non bad email ADDRESS.

But it passes this one:

(e-mail address removed)###%%%

(e-mail address removed)#k

And it blocks:

(e-mail address removed)#om

A simpler and more correct form would be:

var pattern = /^[a-z\d_.-]+@[a-z\d_.-]+\.[a-z]{2,}$/i;

But that does not make it perfect, as better tests can be made.
I want to add a check for a domain name: "mycompany"
such that:

(e-mail address removed)

is a match. and, any other domain is not a match.

For a boolean answer use test():

var pattern = /^[a-z\d_.-]+@mycompany\.com$/i;
var t = '(e-mail address removed)';
alert(pattern.test(t));
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>
, Wed, 20 Feb 2008 18:41:55, Evertjan. <[email protected]>
posted:

A simpler and more correct form would be:

var pattern = /^[a-z\d_.-]+@[a-z\d_.-]+\.[a-z]{2,}$/i;

But that does not make it perfect, as better tests can be made.


Unless one is an ISP or mailer writer concerned with the issuing of new
E-mail addresses, it is not necessarily wise to check for rigorous RFC
compliance. It is easy to think of at least one major software house,
and of at least one major Web site, that has shown definite disregard
(whether by ignorance or malice) for pre-existing standards such as
those in RFCs and of ISO/IEC; they might well have issued addresses
outside what RFCs allowed.

An issuer should comply with the standards, but may not need to allow
all that the RFCs permit.

Conversely, one who checks E-mail addresses entered as data should allow
at least all that the RFCs etc. permit; but may, and might need to,
allow more, if all working addresses are to be accepted. That is, of
course, apart from any specific requirements such as disallowing .dk
because of a specific anti-bacon policy.

Since the only way of telling whether a supplied E-address is actually
good is to use it to send a message and then to get reliable evidence of
true receipt, there's little point in doing more than checking that the
string could be an E-address and is not, for example, blank, a telephone
number, a name, a postal address.

For mailing, testing with /.@./ is probably adequate in practice; but
/\S+@\S+\.\S$/ seems better.
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top