Koden er præcis som i eksemplet
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="
http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>testside</title>
<script language="javascript" type="text/javascript">
var newVal="";
var fdate = null;
var dd=0;
var mm=0;
var repeatRemove=0;
function getCharCode(e){
return (e.which)?e.which:e.keyCode;
}
function restoreVal(eC,fld){
if (eC==8||repeatRemove>0){
if (newVal.length>repeatRemove){
newVal=newVal.substring(0,newVal.length-repeatRemove)
}else{
newVal="";
}
}
repeatRemove=0;
fld.value=newVal;
}
function inputDate(e,fld){
removeChar=false;
newVal=fld.value;
charCode = getCharCode(e);
if ((fld.value.length==2 || fld.value.length==5) && charCode==45){newVal+="-";return true;}
if (fld.value.length==10 || charCode>57 || charCode<48){
return false;
}
newVal=fld.value+String.fromCharCode(charCode);
switch (fld.value.length){
case 0:
if (+newVal>3){repeatRemove++;return false;}
break;
case 1:
if (+newVal>31){repeatRemove++;return false;}
if (+newVal==00){repeatRemove++;return false;}
dd = +newVal;
newVal+="-";
break;
case 2:
newVal=fld.value+"-"+String.fromCharCode(charCode);
if (charCode>49){repeatRemove++;return false;}
break;
case 3:
if (charCode>49){repeatRemove++;return false;}
break;
case 4:
mm = parseInt(newVal.substring(3),10);
if (mm==2 && dd>29 || mm>12 || mm==00){repeatRemove++;return false;}
if (dd==31 && (mm==4 || mm==6 || mm==9 || mm==11)){repeatRemove++;return false;}
newVal+="-";
break;
case 5:
newVal=fld.value+"-"+String.fromCharCode(charCode);
break;
case 6:
if (charCode<50 || charCode>50){repeatRemove++;return false;} //Tillader 2 som første tal i årstal
break;
case 7:
var yy = parseInt(newVal.substring(6));
if (yy<20 || yy>20){repeatRemove++;return false;} //Tillader 20 som første to tal i årstal
break;
case 8:
var yyy = parseInt(newVal.substring(6));
if (yyy>200){repeatRemove++;return false;} //Tillader kun 0 som tredje tal, hvis første to er 2 og 0.
break;
case 9:
var yyyy = parseInt(newVal.substring(6));
if (mm == 2 && dd == 29 && yyyy%4 !=0){repeatRemove+=8;return false;}
}
return true;
}
</script>
</head>
<body>
<form id="frmTest">
dato 1 <INPUT onkeypress="return inputDate(event,this);" onkeydown="if(getCharCode(event)==8)repeatRemove++;" onblur="if(this.value=='')this.value=this.defaultValue;" onkeyup="restoreVal(getCharCode(event),this);this.focus();" onfocus="if(this.value==this.defaultValue)this.value='';" maxLength=10 size="12" value="dd-mm-åååå"> <br />
dato 2 <INPUT onkeypress="return inputDate(event,this);" onkeydown="if(getCharCode(event)==8)repeatRemove++;" onblur="if(this.value=='')this.value=this.defaultValue;" onkeyup="restoreVal(getCharCode(event),this);this.focus();" onfocus="if(this.value==this.defaultValue)this.value='';" maxLength=10 size="12" value="dd-mm-åååå">
</form>
</body>
</html>