I'm using this function below, to validate the date in all date type fields of the form, I call the function in the onBlur event of the txt.
function VerificaData(digData) {
var bissexto = 0;
var data = digData;
var tam = data.length;
if (tam == 10)
{
var dia = data.substr(0, 2);
var mes = data.substr(3, 2);
var ano = data.substr(6, 4);
if ((ano > 1900) || (ano < 2100)) {
switch (mes)
{
case '01':
case '03':
case '05':
case '07':
case '08':
case '10':
case '12':
if (dia <= 31)
{ return true; }
break;
case '04':
case '06':
case '09':
case '11':
if (dia <= 30)
{ return true; }
break;
case '02':
if ((ano % 4 == 0) || (ano % 100 == 0) || (ano % 400 == 0))
{ bissexto = 1; }
if ((bissexto == 1) && (dia <= 29))
{ return true; }
if ((bissexto != 1) && (dia <= 28))
{ return true; }
break;
}
}
}
alert("A Data " + data + " é inválida!");
return false;
}
But I would like to know how do I make the date when the date is invalid, clear the field? I tried to form it would work, if it was a txt and a function, but I use this function for several txts, so the forms I tried and researched do not work. So I call the function:
onBlur="VerificaData(this.value);