i try to allow only number 01 (1) to 53) after / and after 2000 and over….
so i create a regex but it don’t seem to work
on this web page: http://www.regular-expressions.info/javascriptexample.html
i tried it and it work well… but when i test in on a web page
10/2010 , 23/2000
function isValidDate(value, format){
var isValid = true;
try{
var inputVal = $(this).val();
var dateWWYYYYRegex = '^(0[1-9]|[1234][0-9]|5[0-3])[-/.](20)\d\d$';
var reg=new RegExp(dateWWYYYYRegex);
if(!reg.test(value)){
isValid = false;
alert("Invalid");
}
}
catch(error){
isValid = false;
}
return isValid;
}
You have to escape backslashes if you’re going to make a regex from a string. I’d just use regex syntax, since it’s a constant anyway:
The regular expression doesn’t really make any sense, however. It’s not clear what it should be, because your description is also confusing.
edit — OK now that I see what you’re doing, that regex should work, I guess.