HighDots Forums  

Why is this JS code matching underscores?

Javascript JavaScript language (comp.lang.javascript)


Discuss Why is this JS code matching underscores? in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
williamc
 
Posts: n/a

Default Why is this JS code matching underscores? - 09-24-2003 , 10:05 AM








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

Reply With Quote
  #2  
Old   
Douglas Crockford
 
Posts: n/a

Default Re: Why is this JS code matching underscores? - 09-24-2003 , 10:12 AM






Quote:
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



Reply With Quote
  #3  
Old   
williamc
 
Posts: n/a

Default Re: Why is this JS code matching underscores? - 09-24-2003 , 01:12 PM





Douglas Crockford wrote:
Quote:

Too legit to shift.

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

Say what?



--wmc.


Reply With Quote
  #4  
Old   
Dana Cartwright
 
Posts: n/a

Default Re: Why is this JS code matching underscores? - 09-24-2003 , 02:05 PM



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" <temp4_NO_SPAM_ (AT) williamc (DOT) com> wrote

Quote:

Douglas Crockford wrote:


Too legit to shift.

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


Say what?



--wmc.



Reply With Quote
  #5  
Old   
williamc
 
Posts: n/a

Default Re: Why is this JS code matching underscores? - 09-24-2003 , 02:18 PM



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:
Quote:
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" <temp4_NO_SPAM_ (AT) williamc (DOT) com> wrote in message
news:3F71DE3A.3E9C9F2C (AT) williamc (DOT) com...


Douglas Crockford wrote:


Too legit to shift.

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


Say what?



--wmc.

Reply With Quote
  #6  
Old   
Jamie Jackson
 
Posts: n/a

Default Re: Why is this JS code matching underscores? - 09-24-2003 , 02:41 PM



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
<temp4_NO_SPAM_ (AT) williamc (DOT) com> wrote:

Quote:
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" <temp4_NO_SPAM_ (AT) williamc (DOT) com> wrote in message
news:3F71DE3A.3E9C9F2C (AT) williamc (DOT) com...


Douglas Crockford wrote:


Too legit to shift.

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


Say what?



--wmc.


Reply With Quote
  #7  
Old   
williamc
 
Posts: n/a

Default Re: Why is this JS code matching underscores? - 09-25-2003 , 08:03 AM




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

--williamc



Jamie Jackson wrote:
Quote:
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.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.