Need REGEX pattern matching help

Discussion in 'Javascript' started by pbd22, Feb 20, 2008.

  1. pbd22

    pbd22 Guest

    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:



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

    Any gurus know how to add this piece?

    Thanks.
    Peter
     
    pbd22, Feb 20, 2008
    #1
    1. Advertising

  2. pbd22

    Evertjan. Guest

    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:

    ###%%%

    .u#k

    And it blocks:

    #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:
    >
    >
    >
    > 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 = '';
    alert(pattern.test(t));

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Feb 20, 2008
    #2
    1. Advertising

  3. In comp.lang.javascript message <Xns9A4AC8629958Ceejj99@194.109.133.242>
    , Wed, 20 Feb 2008 18:41:55, Evertjan. <>
    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.
     
    Dr J R Stockton, Feb 21, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Xah Lee
    Replies:
    1
    Views:
    971
    Ilias Lazaridis
    Sep 22, 2006
  2. Xah Lee
    Replies:
    8
    Views:
    482
    Ilias Lazaridis
    Sep 26, 2006
  3. Xah Lee
    Replies:
    2
    Views:
    238
    Xah Lee
    Sep 25, 2006
  4. Bobby Chamness
    Replies:
    2
    Views:
    262
    Xicheng Jia
    May 3, 2007
  5. Replies:
    2
    Views:
    415
Loading...

Share This Page