Okay, the Javascript I am posting is HORENDOUSLY LONG because it is checking for many things within the date, but the issue is this: When I put a date in the date field that falls within the min/max year, it submits fine, but it pops up the box sayin "you need to enter the day in dd format" no matter what, where is the error in the script causing this?
_________________________________________
<script LANGUAGE=JAVASCRIPT>
//Script to Validate a date to make sure it is in MM/DD/YYYY format.
//
// Timothy G. Mulle' (Added code to fix error to make year have to be 4 characters long)
//
// 1/20/1998
//Modified by Bianca Berrios 10/15/02 to add VALID DATE check
var minYear = 1950;
var maxYear = 2100;
function msgBox_onError(object, error_message)
{
alert(error_message);
object.focus();
return false;
}
//Main function that calls various other functions
function CheckDate(object)
{
//Returns true if value is a date format or is NULL
//otherwise returns false
if (object.value.length == 0)
return true;
//Returns true if value is a date in the mm/dd/yyyy format
var isplit = object.value.indexOf('/');
//var psplit = object.value.indexof(isplit,isplit+1);
if (isplit == -1 || isplit == object.value.length)
{msgBox_onError(object, "Please enter date in MM/DD/YYYY format"
object.select();
object.focus();
return false;
}
var sMonth = object.value.substring(0, isplit);
var isplit = object.value.indexOf('/', isplit + 1);
if (isplit == -1 || isplit == object.value.length)
{msgBox_onError(object, "Please enter date in MM/DD/YYYY format"
object.select();
object.focus();
return false;
}
var sDay = object.value.substring((sMonth.length + 1), isplit);
var sYear = object.value.substring(isplit + 1);
if (sDay.charAt(0)=="0" && sDay.length>1)sDay=sDay.substring(1)
if (sMonth.charAt(0)=="0" && sMonth.length>1) sMonth=sMonth.substring(1)
for (var i = 1; i <=3; i++) {
if (sYear.charAt(0) == "0" && sYear.length>1) sYear=sYear.substring(1)
var month=parseInt(sMonth)
var day=parseInt(sDay)
var year=parseInt(sYear)
if (sYear.length != 4 || year==0 || year<minYear || year>maxYear)
{msgBox_onError(object, "Please enter a valid year"
object.select();
object.focus();
return false;
}
if (sMonth.length <1 || month<1 || month>12)
{msgBox_onError(object, "Please enter month in mm format"
object.select();
object.focus();
return false;
}
if (sDay.length <1 || year==0 || day<1 || day>31||(month==2
&& day>CheckRange(sYear)) || day > CheckRange(sMonth,1,12))
{msgBox_onError(object, "Please enter day in dd format"
object.select();
object.focus();
return false;
}
function DaysArray {
for (var i = 1; i <= n; i++) {
this = 31
if (i==4 || i==6 || i==9 || i==11) {this = 30}
if (i==2) {this = 29}
}
return this
}
if (object.indexOf(isplit, isplit+1)!=-1 || CheckINteger(object, isplit)==false)
{msgBox_onError(object, "Please enter a valid date"
object.select();
object.focus();
return false;
}
if (!CheckInteger(sMonth))
{msgBox_onError(object, "Month must be an integer"
object.select();
object.focus();
return false;
}
else if (!CheckRange(sMonth, 1, 12))
{msgBox_onError(object, "Month must be from 1-12"
object.select();
object.focus();
return false;
}
else if (!CheckInteger(sYear))
{msgBox_onError(object, "Year must be an integer"
object.select();
object.focus();
return false;
}
else if (!CheckRange(sYear, 0, null))
{msgBox_onError(object, "Year must be >= 0"
object.select();
object.focus();
return false;
}
else if (!CheckInteger(sDay))
{msgBox_onError(object, "Day must be an integer"
object.select();
object.focus();
return false;
}
else if (!CheckDay(sYear, sMonth, sDay))
{msgBox_onError(object, "Day does not exist in specified month"
object.select();
object.focus();
return false;
}
else if (!CheckDay(object_value)==0)
{msgBox_onError(object, "Please enter a valid date"
object.select();
object.focus();
return false;
}
else
return true;
}
function CheckDay(checkYear, checkMonth, checkDay)
{
maxDay = 31;
if (checkMonth == 4 || checkMonth == 6 || checkMonth == 9 || checkMonth == 11)
maxDay = 30;
else if (checkMonth == 2)
{
if (checkYear % 4 > 0)
maxDay =28;
else if (checkYear % 100 == 0 && checkYear % 400 > 0)
maxDay = 28;
else
maxDay = 29;
}
return CheckRange(checkDay, 1, maxDay); //check day
}
function CheckInteger(object_value)
{
//Returns true if value is a number or is NULL
//otherwise returns false
if (object.value.length == 0)
return true;
//Returns true if value is an integer defined as
// having an optional leading + or -.
// otherwise containing only the characters 0-9.
var decimal_format = ".";
var check_char;
//The first character can be + - blank or a digit.
check_char = object.value.indexOf(decimal_format)
//Was it a decimal?
if (check_char < 1)
return CheckNumber(object_value);
else
return false;
}
function NumberRange(object_value, min_value, max_value)
{
// check minimum
if (min_value != null)
{
if (object_value < min_value)
return false;
}
// check maximum
if (max_value != null)
{
if (object_value > max_value)
return false;
}
//All tests passed, so...
return true;
}
function CheckNumber(object_value)
{
//Returns true if value is a number or is NULL
//otherwise returns false
if (object.value.length == 0)
return true;
//Returns true if value is a number defined as
// having an optional leading + or -.
// having at most 1 decimal point.
// otherwise containing only the characters 0-9.
var start_format = " .+-0123456789";
var number_format = " .0123456789";
var check_char;
var decimal = false;
var trailing_blank = false;
var digits = false;
//The first character can be + - . blank or a digit.
check_char = start_format.indexOf(object.value.charAt(0))
//Was it a decimal?
if (check_char == 1)
decimal = true;
else if (check_char < 1)
return false;
//Remaining characters can be only . or a digit, but only one decimal.
for (var i = 1; i < object.value.length; i++)
{
check_char = number_format.indexOf(object.value.charAt(i))
if (check_char < 0)
return false;
else if (check_char == 1)
{
if (decimal) // Second decimal.
return false;
else
decimal = true;
}
else if (check_char == 0)
{
if (decimal || digits)
trailing_blank = true;
// ignore leading blanks
}
else if (trailing_blank)
return false;
else
digits = true;
}
//All tests passed, so...
return true
}
function CheckRange(object_value, min_value, max_value)
{
//if value is in range then return true else return false
if (object.value.length == 0)
return true;
if (!CheckNumber(object_value))
{
return false;
}
else
{
return (NumberRange((eval(object_value)), min_value, max_value));
}
//All tests passed, so...
return true;
}
}
</SCRIPT>
bb
_________________________________________
<script LANGUAGE=JAVASCRIPT>
//Script to Validate a date to make sure it is in MM/DD/YYYY format.
//
// Timothy G. Mulle' (Added code to fix error to make year have to be 4 characters long)
//
// 1/20/1998
//Modified by Bianca Berrios 10/15/02 to add VALID DATE check
var minYear = 1950;
var maxYear = 2100;
function msgBox_onError(object, error_message)
{
alert(error_message);
object.focus();
return false;
}
//Main function that calls various other functions
function CheckDate(object)
{
//Returns true if value is a date format or is NULL
//otherwise returns false
if (object.value.length == 0)
return true;
//Returns true if value is a date in the mm/dd/yyyy format
var isplit = object.value.indexOf('/');
//var psplit = object.value.indexof(isplit,isplit+1);
if (isplit == -1 || isplit == object.value.length)
{msgBox_onError(object, "Please enter date in MM/DD/YYYY format"
object.select();
object.focus();
return false;
}
var sMonth = object.value.substring(0, isplit);
var isplit = object.value.indexOf('/', isplit + 1);
if (isplit == -1 || isplit == object.value.length)
{msgBox_onError(object, "Please enter date in MM/DD/YYYY format"
object.select();
object.focus();
return false;
}
var sDay = object.value.substring((sMonth.length + 1), isplit);
var sYear = object.value.substring(isplit + 1);
if (sDay.charAt(0)=="0" && sDay.length>1)sDay=sDay.substring(1)
if (sMonth.charAt(0)=="0" && sMonth.length>1) sMonth=sMonth.substring(1)
for (var i = 1; i <=3; i++) {
if (sYear.charAt(0) == "0" && sYear.length>1) sYear=sYear.substring(1)
var month=parseInt(sMonth)
var day=parseInt(sDay)
var year=parseInt(sYear)
if (sYear.length != 4 || year==0 || year<minYear || year>maxYear)
{msgBox_onError(object, "Please enter a valid year"
object.select();
object.focus();
return false;
}
if (sMonth.length <1 || month<1 || month>12)
{msgBox_onError(object, "Please enter month in mm format"
object.select();
object.focus();
return false;
}
if (sDay.length <1 || year==0 || day<1 || day>31||(month==2
&& day>CheckRange(sYear)) || day > CheckRange(sMonth,1,12))
{msgBox_onError(object, "Please enter day in dd format"
object.select();
object.focus();
return false;
}
function DaysArray {
for (var i = 1; i <= n; i++) {
this = 31
if (i==4 || i==6 || i==9 || i==11) {this = 30}
if (i==2) {this = 29}
}
return this
}
if (object.indexOf(isplit, isplit+1)!=-1 || CheckINteger(object, isplit)==false)
{msgBox_onError(object, "Please enter a valid date"
object.select();
object.focus();
return false;
}
if (!CheckInteger(sMonth))
{msgBox_onError(object, "Month must be an integer"
object.select();
object.focus();
return false;
}
else if (!CheckRange(sMonth, 1, 12))
{msgBox_onError(object, "Month must be from 1-12"
object.select();
object.focus();
return false;
}
else if (!CheckInteger(sYear))
{msgBox_onError(object, "Year must be an integer"
object.select();
object.focus();
return false;
}
else if (!CheckRange(sYear, 0, null))
{msgBox_onError(object, "Year must be >= 0"
object.select();
object.focus();
return false;
}
else if (!CheckInteger(sDay))
{msgBox_onError(object, "Day must be an integer"
object.select();
object.focus();
return false;
}
else if (!CheckDay(sYear, sMonth, sDay))
{msgBox_onError(object, "Day does not exist in specified month"
object.select();
object.focus();
return false;
}
else if (!CheckDay(object_value)==0)
{msgBox_onError(object, "Please enter a valid date"
object.select();
object.focus();
return false;
}
else
return true;
}
function CheckDay(checkYear, checkMonth, checkDay)
{
maxDay = 31;
if (checkMonth == 4 || checkMonth == 6 || checkMonth == 9 || checkMonth == 11)
maxDay = 30;
else if (checkMonth == 2)
{
if (checkYear % 4 > 0)
maxDay =28;
else if (checkYear % 100 == 0 && checkYear % 400 > 0)
maxDay = 28;
else
maxDay = 29;
}
return CheckRange(checkDay, 1, maxDay); //check day
}
function CheckInteger(object_value)
{
//Returns true if value is a number or is NULL
//otherwise returns false
if (object.value.length == 0)
return true;
//Returns true if value is an integer defined as
// having an optional leading + or -.
// otherwise containing only the characters 0-9.
var decimal_format = ".";
var check_char;
//The first character can be + - blank or a digit.
check_char = object.value.indexOf(decimal_format)
//Was it a decimal?
if (check_char < 1)
return CheckNumber(object_value);
else
return false;
}
function NumberRange(object_value, min_value, max_value)
{
// check minimum
if (min_value != null)
{
if (object_value < min_value)
return false;
}
// check maximum
if (max_value != null)
{
if (object_value > max_value)
return false;
}
//All tests passed, so...
return true;
}
function CheckNumber(object_value)
{
//Returns true if value is a number or is NULL
//otherwise returns false
if (object.value.length == 0)
return true;
//Returns true if value is a number defined as
// having an optional leading + or -.
// having at most 1 decimal point.
// otherwise containing only the characters 0-9.
var start_format = " .+-0123456789";
var number_format = " .0123456789";
var check_char;
var decimal = false;
var trailing_blank = false;
var digits = false;
//The first character can be + - . blank or a digit.
check_char = start_format.indexOf(object.value.charAt(0))
//Was it a decimal?
if (check_char == 1)
decimal = true;
else if (check_char < 1)
return false;
//Remaining characters can be only . or a digit, but only one decimal.
for (var i = 1; i < object.value.length; i++)
{
check_char = number_format.indexOf(object.value.charAt(i))
if (check_char < 0)
return false;
else if (check_char == 1)
{
if (decimal) // Second decimal.
return false;
else
decimal = true;
}
else if (check_char == 0)
{
if (decimal || digits)
trailing_blank = true;
// ignore leading blanks
}
else if (trailing_blank)
return false;
else
digits = true;
}
//All tests passed, so...
return true
}
function CheckRange(object_value, min_value, max_value)
{
//if value is in range then return true else return false
if (object.value.length == 0)
return true;
if (!CheckNumber(object_value))
{
return false;
}
else
{
return (NumberRange((eval(object_value)), min_value, max_value));
}
//All tests passed, so...
return true;
}
}
</SCRIPT>
bb