Hello good morning I have the next function that validates dates without the "/" example 010218
that would be 01/02/2018
, also if only 4 characters come I add it through php the year. Obviously the date armo by .substr
. The help I need basically would be to restrict tomorrow. For example, if today is 13/04/2018 (130418)
that a date higher than that day can not be added. Example the next day (140418)
. Thank you very much!
function ValidarF() {
var date1Var = $("#Fecha").val();
var date1;
var mes = date1Var.toString().substr(2,2);
var dias = date1Var.toString().substr(0,2);
var anio = date1Var.toString().substr(4,2);
//Si vienen 3 caracteres tiro error.
if(date1Var.length==3)
{
swal("","Fecha incorrecta","warning");
}
//Hago lo mismo con 5.
if(date1Var.length==5)
{
swal("","Fecha incorrecta","warning");
}
if(date1Var.length==4)
{
//En este caso valido que el mes sea el rango de 1 a 12 y dias de 1 a 31
if (mes<1 ||mes>12 || dias<1 ||dias>31)
{
swal("","Fecha incorrecta","warning");
}
}
if(date1Var.length==6)
{
if (mes<1 || mes>12 || dias<1 ||dias>31)
{
swal("","Fecha incorrecta","warning");
}
}
//Seteo el año hasta 2018
if (date1='20'+anio>2018)
{
swal("","Fecha incorrecta","warning");
}
}
PHP:
$date1Var = $_REQUEST["Fecha"];
if(strlen($date1Var)==4) {
$date1=date("Y").'-'.substr($date1Var,2,2).'-'.substr($date1Var,0,2);
} elseif(strlen($date1Var)==6) {
$date1='20'.substr($date1Var,4,2).'-'.substr($date1Var,2,2).'-'.substr($date1Var,0,2);
} else {
$date1 = date('Y-m-d');
}