I'm trying to validate a date field of the 'txtDat' id, as follows:
I want you to tell me a date with a date earlier than today, show alert("Por favor, insira uma data futura.")
, and if you tell me a date longer than 30 days, show alert("Por favor, insira uma data menor que 30 dias.")
, or, if not, it follows.
As a base I have this code that I got here in the stack overflow to validate under and under 65
var data_ano = cad.txtDat.value;
var separa = ~data_ano.indexOf("/") ? "/" : "-";
var data_array = Number(data_ano.split(separa).filter(function(e){
return e.length == 4;
}));
var este_ano = (new Date()).getFullYear();
if(data_array > este_ano-18 || data_array < este_ano-65){
alert("É preciso ter 18 anos e menos de 65 anos.");
return;
}
I tried instead of getfullyear
o getday
, tried several other things but could not do.