3
I am using this function below, to validate the date in all fields of the form date type, call the function in txt onBlur event.
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 so that when the date is invalid, clear the field ? I tried to form that it would work, if it was a txt and a function, but I use this function for several txts, so the ways I tried, and I researched didn’t work. That’s what I call the job:
onBlur="VerificaData(this.value);
Hello Mariana! This date check function seems to me unnecessarily complex. You can give examples of dates she receives and what she intends to detect wrong?
– Sergio