Regular Expression HELP -- thanks
Hello All,
I am rather new to regular expressions. I have this regualr expression to check if the number entered is between 1 and 366:
var regVal= new RegularExp("^[1-366]$");
from everything i've read it seems to work but it only works on certain numbers and says most other numbers are wrong
I have attached my code.
it seems to me that the expression is formed incorectly, beacue when i printed the result of
regVal.test(document.f1.duration.value)
to the screen it is actually deeming those numbers (for example 4) as not a match, so its not the if block or alert statement misfiring.
if you could take a look at my code that would be very helpfull, its very short code.. and this is driving me bonkers...lol
thanks in advance
code:
---------
function val2()
{
var regVal;
regVal= new RegExp("^[1-366]$");
if (!regVal.test(document.f1.duration.value))
{
alert('Please enter a duration between 1 and 366 days');
document.write (regVal.test(document.f1.duration.value));
//pls note the above line prints the result of the match to the screen . Every time the alert text says the match was false it really was false, not just a misfire of the alert text.
}
}
|