di solito uso questo script che ho fatto io :

1) bisogna includere il file di controllo format data




2) Nel controllo del Submit del form si esegue questo controllo :

if (document.all.dta_iscrizione.value == ""){
messaggio = "Data iscrizione
obbligatoria."
NewWindow("../../../Include/PopUpMessaggi.asp?msg="+ messaggio,"dataitem",'110','230');
return false;
}else{
ctrlDta = formatoData(document.all.dta_iscrizione.value)
if (ctrlDta != "OK"){
messaggio = "Formato data iscrizione
errato."
NewWindow("../../../Include/PopUpMessaggi.asp?msg="+messaggio,"dataitem",'110' ,'230');
return false;
}
}


3) questo è il codice dell'include formatData.js :



// ****************************
// FUNZIONE PER CONTROLLO DATE
// ****************************
function formatoData(parametro){
dtaIni = ""
dtaIni = parametro

giorno = dtaIni.substring(0,2)
if (giorno.substring(0,1) == "0"){
giorno = giorno.substring(1,2)
}

mese = dtaIni.substring(3,5)
if (mese.substring(0,1) == "0"){
mese = mese.substring(1,2)
}

anno = dtaIni.substring(6,10)


if (dtaIni.length != 10){ // CONTROLLO LUNGHEZZA ESATTA DATA
return "ERRORE LUNGHEZZA"
}
if (dtaIni.substr(0,1) == "/"){ // CONTROLLO BARRA IN POSIZOINE ERRATA
return "ERRORE BARRA 1"
}
if (dtaIni.substr(1,1) == "/"){ // CONTROLLO BARRA IN POSIZOINE ERRATA
return "ERRORE BARRA 2"
}
if (dtaIni.substr(3,1) == "/"){ // CONTROLLO BARRA IN POSIZOINE ERRATA
return "ERRORE BARRA 3"
}
if (dtaIni.substr(4,1) == "/"){ // CONTROLLO BARRA IN POSIZOINE ERRATA
return "ERRORE BARRA 4"
}
if (dtaIni.substr(6,1) == "/"){ // CONTROLLO BARRA IN POSIZOINE ERRATA
return "ERRORE BARRA 5"
}
if (dtaIni.substr(7,1) == "/"){ // CONTROLLO BARRA IN POSIZOINE ERRATA
return "ERRORE BARRA 6"
}
if (dtaIni.substr(8,1) == "/"){ // CONTROLLO BARRA IN POSIZOINE ERRATA
return "ERRORE BARRA 7"
}
if (dtaIni.substr(9,1) == "/"){ // CONTROLLO BARRA IN POSIZOINE ERRATA
return "ERRORE BARRA 8"
}
if (dtaIni.substr(2,1) != "/"){ // CONTROLLO BARRA DOPO GIORNO
return "ERRORE BARRA 9"
}
if (dtaIni.substr(5,1) != "/"){ // CONTROLLO BARRA DOPO MESE
return "ERRORE BARRA 10"
}
if (parseInt(mese) < 1){ // CONTROLLO LIMITE MINIMO MESE
return "ERRORE MESE MIN"
}
if (parseInt(mese) > 12){ // CONTROLLO LIMITE MASSIMO MESE
return "ERRORE MESE MAX"
}
if (parseInt(dtaIni.substr(6,4)) < 1900){ // CONTROLLO LIMITE MINIMO ANNO
return "ERRORE ANNO MIN"
}
if (parseInt(dtaIni.substr(6,4)) > 2100){ // CONTROLLO LIMITE MASSIMO ANNO
return "ERRORE ANNO MAX"
}
if (parseInt(giorno) < 1){ // CONTROLLO LIMITE MINIMO GIORNO
return "ERRORE GIORNO MIN"
}
if (parseInt(mese) == 1){ // CONTROLLO LIMITE GIORNI GENNAIO
if (parseInt(giorno) > 31){
return "ERRORE GENNAIO MAX"
}
}
if (parseInt(mese) == 2){ // CONTROLLO LIMITE GIORNI FEBBRAIO

// CALCOLO BISESTILE ( divisibile per 4 e non per 100, o , divisibile per 400 )
yr = parseInt(anno)
rem = yr % 4;
if(rem == 0) {
div4 = true;
} else {
div4 = false;
}
rem = yr % 100;
if(rem == 0) {
div100 = true;
} else {
div100 = false;
}
rem = yr % 400;
if(rem == 0) {
div400 = true;
} else {
div400 = false;
}
if ( (div4 == true && div100 == false) || (div400 == true) ){
if (parseInt(giorno) > 29){
return "ERRORE ANNO BISESTILE"
}
} else {
if (parseInt(giorno) > 28){
return "ERRORE ANNO NON BISESTILE"
}
}
}
if (parseInt(mese) == 3){ // CONTROLLO LIMITE GIORNI MARZO
if (parseInt(giorno) > 31){
return "ERRORE MARZO MAX"
}
}
if (parseInt(mese) == 4){ // CONTROLLO LIMITE GIORNI APRILE
if (parseInt(giorno) > 30){
return "ERRORE APRILE MAX"
}
}
if (parseInt(mese) == 5){ // CONTROLLO LIMITE GIORNI MAGGIO
if (parseInt(giorno) > 31){
return "ERRORE MAGGIO MAX"
}
}
if (parseInt(mese) == 6){ // CONTROLLO LIMITE GIORNI GIUGNO
if (parseInt(giorno) > 30){
return "ERRORE GIUGNO MAX"
}
}
if (parseInt(mese) == 7){ // CONTROLLO LIMITE GIORNI LUGLIO
if (parseInt(giorno) > 31){
return "ERRORE LUGLIO MAX"
}
}
if (parseInt(mese) == 8){ // CONTROLLO LIMITE GIORNI AGOSTO
if (parseInt(giorno) > 31){
return "ERRORE AGOSTO MAX"
}
}
if (parseInt(mese) == 9){ // CONTROLLO LIMITE GIORNI SETTEMBRE
if (parseInt(giorno) > 30){
return "ERRORE SETTEMBRE MAX"
}
}
if (parseInt(mese) == 10){ // CONTROLLO LIMITE GIORNI OTTOBRE
if (parseInt(giorno) > 31){
return "ERRORE OTTOBRE MAX"
}
}
if (parseInt(mese) == 11){ // CONTROLLO LIMITE GIORNI NOVEMBRE
if (parseInt(giorno) > 30){
return "ERRORE NOVEMBRE MAX"
}
}
if (parseInt(mese) == 12){ // CONTROLLO LIMITE GIORNI DICEMBRE
if (parseInt(giorno) > 31){
return "ERRORE DICEMBRE MAX"
}
}

return "OK"
}

ciao !!!