Qualche giorno fa ho visto un modo interessante di validazione data, proposto (non ricordo bene
) o da Xinod o da Br1 ed ho preso spunto da quella risposta per costruire un validatore data nel formato YYYYMMDD.
Ne ho fatto una funzione che sembra funzionare, ma ho la sensazione che sia ampollosa.
Insomma, chiedo che se possibile, venga corretta :master:
codice:
function CustomValidator1_validate(value)
{
try
{
if(value.length != 8) {return false;}
var d = new Date(parseInt(value.substr(0, 4),10) ,parseInt(value.substr(4, 2),10)-1,parseInt(value.substr(6, 2),10));
var anno = d.getFullYear();
var mese = (parseInt(d.getMonth(),10) + 1).toString(); if(mese.length == 1) mese = "0" + mese;
var giorno = (parseInt(d.getDate(),10)).toString(); if(giorno.length == 1) giorno = "0" + giorno;
var s = anno + "" + mese + "" + giorno;
if(s != value) {return false;};
}
catch(e)
{
return false;
}
return true;
}