<html>
<head>
<title>Year Validation-JAVASCRIPT</title>
<script type="text/javascript">
// checks to see if the data passed in is a 4 digit year between now and 1900
function checkIsValidYear(_data)
{
var _thisYear = new Date().getFullYear();
if (_data.length != 4){
alert( "This is not valid");
return false;
}
if (!_data.match(/\d{4}/)){
alert( "This is not valid");
return false;
}
if (parseInt(_data) > _thisYear || parseInt(_data) < 1900){
alert( "This is not valid");
return false;
}
return true;
}
</script>
</head>
<body>
<form name="myForm">
<input type="text" name="theYear" maxlength="4" value="" onchange="return checkIsValidYear(this.value) ;"/>
</body>
</html>