View Single Post
Old Oct 11th, 2005, 12:45 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You should read the forum FAQ/rules and one of the "How to Post..." threads. They clearly indicate that you should put you code in tags to preserve the indentation. Anything else is rude to your potential respondents.

That said, trying to validate that a number is within a certain range by using regular expressions is like trying to swat a spider with a track hoe. Simply compare it against the upper and lower limits after ascertaining that it is, indeed, a number, with one of the available JS tests.

Your particular expression range, [1-366], says that you have a valid character set including the characters representing the numbers 1-3 (that would be 1,2, and 3), plus the character representing the number, 6. A number expressed as a string with any digits other than those will fail.

JS is a weakly typed language. You still need to know, occassionally, the difference between a string representing a number, and an actual number.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote