DI CHE COSA AVRETE BISOGNO:
Conoscenza di
JavaScript -
un browser
che supporti JavaScript -
NOTEPAD
CODICE:
<html>
<head>
<script language="javascript">
function checkDate(sDate)
{
var startIdx = 0;
var pos = sDate.indexOf("/",startIdx);
var parsDate = new Array();
var count = 0;
var bError = false;
if ( sDate.length != 10 ) return true;
do
{
parsDate[count] = sDate.substring(startIdx,pos);
count ++;
startIdx = pos + 1;
pos = sDate.indexOf("/",startIdx);
}
while (pos > 0)
parsDate[count] = sDate.substring(startIdx);
if (parsDate.length != 3) return true;
if (isNaN(parsDate[2]) || parsDate[2] < 1900 || parsDate[2] > 9999)
return true;
if (isNaN(parsDate[1]) || parsDate[1] > 12 || parsDate[1] < 1) return
true;
if (isNaN(parsDate[0]) || parsDate[0] > 31 || parsDate[0] < 1) return
true;
if (parsDate[1] == 1 && parsDate[0] > 31 ) return true;
if (parsDate[2] == 2004 && parsDate[1] == 2 && parsDate[0] == 29 )
return false;
if (parsDate[2] == 2008 && parsDate[1] == 2 && parsDate[0] == 29 )
return false;
if (parsDate[2] == 2012 && parsDate[1] == 2 && parsDate[0] == 29 )
return false;
if (parsDate[1] == 2 && parsDate[0] > 28 ) return true;
if (parsDate[1] == 3 && parsDate[0] > 31 ) return true;
if (parsDate[1] == 4 && parsDate[0] > 30 ) return true;
if (parsDate[1] == 5 && parsDate[0] > 31 ) return true;
if (parsDate[1] == 6 && parsDate[0] > 30 ) return true;
if (parsDate[1] == 7 && parsDate[0] > 31 ) return true;
if (parsDate[1] == 8 && parsDate[0] > 31 ) return true;
if (parsDate[1] == 9 && parsDate[0] > 30 ) return true;
if (parsDate[1] == 10 && parsDate[0] > 31 ) return true;
if (parsDate[1] == 11 && parsDate[0] > 30 ) return true;
if (parsDate[1] == 12 && parsDate[0] > 31 ) return true;
return false;
}
</script>
</head>
<body>
<input type="text" name="Testo">
<input type="button" value="Controlla" onclick="document.write(checkDate(Testo.value))">
<form></form>
</body>
</html>
<<
INDIETRO
|