ok ecco un po' di codice:
Codice PHP:
function controllo_data(stringa){
var espressione = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
if (!espressione.test(stringa)) {
return false;
}else{
anno = parseInt(stringa.substr(6),10);
mese = parseInt(stringa.substr(3, 2),10);
giorno = parseInt(stringa.substr(0, 2),10);
var data=new Date(anno, mese-1, giorno);
if(data.getFullYear()==anno && data.getMonth()+1==mese && data.getDate()==giorno){
return true;
}else{
return false;
}
}
};
function modulo_strutture(){
var datackin=document.modulo_tipodata_str.sd.value;
var datackout=document.modulo_tipodata_str.ed.value;
var dateok="";
if (datackin != "" && datackout != "") {
if(!controllo_data(datackin) && !controllo_data(datackout)){
alert('Inserire le date nel formato gg/mm/aaaa');
return -1;
}
if(!confronta_data(datackin,datackout)){
alert('La data di inizio deve essere precedente quella di fine');
return -1;
}
anno1 = parseInt(datackin.substr(6),10);
mese1 = parseInt(datackin.substr(3, 2),10);
giorno1 = parseInt(datackin.substr(0, 2),10);
anno2 = parseInt(datackout.substr(6),10);
mese2 = parseInt(datackout.substr(3, 2),10);
giorno2 = parseInt(datackout.substr(0, 2),10);
var dataok1=new Date(anno1, mese1-1, giorno1);
var dataok2=new Date(anno2, mese2-1, giorno2);
differenza = dataok2-dataok1;
//giorni_differenza = new String(differenza/86400000);
//alert(giorni_differenza+' giorni di differenza');
//return giorni_differenza;
if ((differenza/86400000) > 30) {
alert("La data del check out non può essere superiore di 30 giorni alla data del check in")
} else {
dateok="ok"
}
} else {
dateok="ok"
}
ecc...