I tried validating date with the following code:-
function d(id){
var n= document.getElementById(id);
var re=/^(?:(0[1-9]|1[012])[\- \/.](0[1-9]|[12][0-9]|3[01])[\- \/.](19|20)[0-9]{2})$/;
if (re.test(n.value))
{
n.style.backgroundColor="#52F40C";
}
else
{
window.alert("Invalid date");
n.style.backgroundColor="#F40C0C";
n.focus();
n.value="";
}
}
But it isn’t working. What is the problem with this code?
try this