Why is this JS code matching underscores?

Discussion in 'Javascript' started by williamc, Sep 24, 2003.

  1. williamc

    williamc Guest

    The same regexp that seems to be working on the server side in Perl
    seems to be failing on the client side in JavaScript... I want to match
    a string that's exactly 7 alpha-numeric characters. So I used...

    var reSCode = /^[a-zA-z0-9]{7}$/;

    ....

    if (frm.elements["ServiceCode"].value == "") {
    alert("Service Code is a required field.");
    return;
    } else {
    strServiceCode = frm.elements["ServiceCode"].value;
    if (!(reSCode.test(strServiceCode))) {
    alert("The Service Code that you entered blah blah...");
    return;
    }
    }

    However, when the user enters an underscore re.test() seems to be
    returning true... Can somebody explain why?

    thx,

    --williamc
     
    williamc, Sep 24, 2003
    #1
    1. Advertising

  2. > The same regexp that seems to be working on the server side in Perl
    > seems to be failing on the client side in JavaScript... I want to match
    > a string that's exactly 7 alpha-numeric characters. So I used...
    >
    > var reSCode = /^[a-zA-z0-9]{7}$/;


    Too legit to shift.

    var reSCode = /^[a-zA-Z0-9]{7}$/;

    http://www.crockford.com/javascript/lint.html
     
    Douglas Crockford, Sep 24, 2003
    #2
    1. Advertising

  3. williamc

    williamc Guest

    Douglas Crockford wrote:
    >
    >
    > Too legit to shift.
    >
    > var reSCode = /^[a-zA-Z0-9]{7}$/;



    Say what?

    :)

    --wmc.
     
    williamc, Sep 24, 2003
    #3
  4. OK, so "Too legit to shift." is pretty cryptic, but what he correctly
    pointed out is that these two lines:

    var reSCode = /^[a-zA-z0-9]{7}$/; // Your version
    var reSCode = /^[a-zA-Z0-9]{7}$/; // Douglas Crokford's version.

    are not the same, and therein lies your problem.

    "williamc" <> wrote in message
    news:...
    >
    >
    > Douglas Crockford wrote:
    > >
    > >
    > > Too legit to shift.
    > >
    > > var reSCode = /^[a-zA-Z0-9]{7}$/;

    >
    >
    > Say what?
    >
    > :)
    >
    > --wmc.
     
    Dana Cartwright, Sep 24, 2003
    #4
  5. williamc

    williamc Guest

    Doh...

    One of those staring right at deals. Altho I still don't know what "Too
    legit to shift" means...

    thx all,

    -wmc...



    Dana Cartwright wrote:
    >
    > OK, so "Too legit to shift." is pretty cryptic, but what he correctly
    > pointed out is that these two lines:
    >
    > var reSCode = /^[a-zA-z0-9]{7}$/; // Your version
    > var reSCode = /^[a-zA-Z0-9]{7}$/; // Douglas Crokford's version.
    >
    > are not the same, and therein lies your problem.
    >
    > "williamc" <> wrote in message
    > news:...
    > >
    > >
    > > Douglas Crockford wrote:
    > > >
    > > >
    > > > Too legit to shift.
    > > >
    > > > var reSCode = /^[a-zA-Z0-9]{7}$/;

    > >
    > >
    > > Say what?
    > >
    > > :)
    > >
    > > --wmc.
     
    williamc, Sep 24, 2003
    #5
  6. That's when you feel that with your parachute pants, your mind for
    rhyme, and your two hype feet, you can't be bothered to hit the
    "shift" key.

    Jamie ;-)
    WebMaster, MCHammerUSA.com
    http://www.mchammerusa.com/

    Okay, so not really.

    On Wed, 24 Sep 2003 19:18:17 GMT, williamc
    <> wrote:

    >Doh...
    >
    >One of those staring right at deals. Altho I still don't know what "Too
    >legit to shift" means...
    >
    >thx all,
    >
    >-wmc...
    >
    >
    >
    >Dana Cartwright wrote:
    >>
    >> OK, so "Too legit to shift." is pretty cryptic, but what he correctly
    >> pointed out is that these two lines:
    >>
    >> var reSCode = /^[a-zA-z0-9]{7}$/; // Your version
    >> var reSCode = /^[a-zA-Z0-9]{7}$/; // Douglas Crokford's version.
    >>
    >> are not the same, and therein lies your problem.
    >>
    >> "williamc" <> wrote in message
    >> news:...
    >> >
    >> >
    >> > Douglas Crockford wrote:
    >> > >
    >> > >
    >> > > Too legit to shift.
    >> > >
    >> > > var reSCode = /^[a-zA-Z0-9]{7}$/;
    >> >
    >> >
    >> > Say what?
    >> >
    >> > :)
    >> >
    >> > --wmc.
     
    Jamie Jackson, Sep 24, 2003
    #6
  7. williamc

    williamc Guest

    Ok, I'm parting to hit it...

    --williamc



    Jamie Jackson wrote:
    >
    > That's when you feel that with your parachute pants, your mind for
    > rhyme, and your two hype feet, you can't be bothered to hit the
    > "shift" key.
    >
     
    williamc, Sep 25, 2003
    #7
    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. Laura
    Replies:
    1
    Views:
    413
    Laura
    Jun 3, 2004
  2. J. Hall
    Replies:
    4
    Views:
    1,151
    J. Hall
    Jun 3, 2004
  3. Andy Glew
    Replies:
    84
    Views:
    1,926
    Dave Vandervies
    Oct 28, 2003
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,090
    Smokey Grindel
    Dec 2, 2006
  5. David Filmer
    Replies:
    22
    Views:
    550
    Rainer Weikusat
    Jan 10, 2012
Loading...

Share This Page