Hello good afternoon everyone has my function that validates a date without "/" example: 010218
would be ( 01/02/2018
).
What I basically need to add a validation but which does not come out, which would be to throw an alert like the others but if the date entered is after 2 months to today's date, for example today is 14/06/2018
(14062018) ( I would have to leave until 14/04/2018
(140418) then pulls alert, I burned my head and it does not come out I would appreciate a hand
function validarFecha2()
{
var date1Var = $("#date1").val();
var ano = (new Date).getFullYear();
var Mes12 = (new Date).getMonth();
var mes = date1Var.toString().substr(2,2);
var dias = date1Var.toString().substr(0,2);
var anio = date1Var.toString().substr(4,2);
if(date1Var.length!==4 && date1Var.length!==6) {
swal("","Fecha debe contener 4 o 6 dígitos","warning");
}
if(date1Var.length==4) {
$("#date1").val(date1Var+'18');
anio='18'
}
if (mes<1 || mes>12 || dias<1 ||dias>31) {
swal("","El Mes debe ser entre 01 y 12","warning");
}
anio='20'+anio;
if (anio>2018)
{
swal("","El año no puede ser mayor a 2018","warning");
}
var fecha_formateada=[dias,mes,anio].join('-');
var fecha_iso = [anio,mes,dias].join('-');
var date=new Date(fecha_iso);
//si es mayor a fecha de hoy en dia valido
if(date.getTime()>Date.now()) {
swal("","La fecha no puede ser mayor a hoy","warning");
}
}