469,331 Members | 1,754 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,331 developers. It's quick & easy.

Need REGEX pattern matching help

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:

pe***@mycompany.com

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

Any gurus know how to add this piece?

Thanks.
Peter
Feb 20 '08 #1
1 1299
In comp.lang.javascript message <Xn********************@194.109.133.242>
, Wed, 20 Feb 2008 18:41:55, Evertjan. <ex**************@interxnl.net>
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.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- FAQqish topics, acronyms & links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Feb 21 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Alan Pretre | last post: by
5 posts views Thread by Bill Cohagan | last post: by
7 posts views Thread by bill tie | last post: by
1 post views Thread by Brian Patterson | last post: by
17 posts views Thread by Mark | last post: by
3 posts views Thread by MCH | last post: by
16 posts views Thread by Mark Chambers | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.