Why is this JS code matching underscores?

W

williamc

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
 
D

Dana Cartwright

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 said:
Douglas said:
Too legit to shift.

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


Say what?

:)

--wmc.
 
W

williamc

Doh...

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

thx all,

-wmc...



Dana said:
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 said:
Douglas said:
Too legit to shift.

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


Say what?

:)

--wmc.
 
J

Jamie Jackson

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.

Doh...

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

thx all,

-wmc...



Dana said:
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 said:
Douglas Crockford wrote:


Too legit to shift.

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


Say what?

:)

--wmc.
 

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,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top