/****************************************************************** convert_date() Function to convert supplied dates to format - dd/mm/yyyy. Valid input dates = ddmmyy, ddmmmyy, ddmmyyyy, ddmmmyyyy, d/m/yy, dd/m/yy, d/mm/yy, dd/mm/yy, d/mmm/yy, dd/mmm/yy, d/m/yyyy, dd/m/yyyy, d/mm/yyyy, dd/mm/yyyy, d/mmm/yyyy, dd/mmm/yyyy Valid date seperators = '-','.','/',' ',':','_',',' Calls convert_month() invalid_date() validate_date() validate_year() Author: Simon Kneafsey Email: simonkneafsey@hotmail.com WebSite: www.simonkneafsey.co.uk Date Created: 4/9/00 Notes: Please feel free to use/edit this script. If you do please keep my comments and details intact and notify me via a quick Email to the address above. Enjoy! *******************************************************************/ function convert_date(field1) { var fLength = field1.value.length; // Length of supplied field in characters. var divider_values = new Array ('-','.','/',' ',':','_',','); // Array to hold permitted date seperators. Add in '\' value var array_elements = 7; // Number of elements in the array - divider_values. var day1 = new String(null); // day value holder var month1 = new String(null); // month value holder var year1 = new String(null); // year value holder var divider1 = null; // divider holder var outdate1 = null; // formatted date to send back to calling field holder var counter1 = 0; // counter for divider looping var divider_holder = new Array ('0','0','0'); // array to hold positions of dividers in dates var s = String(field1.value); // supplied date value variable //If field is empty do nothing if ( fLength == 0 ) { return true; } // Deal with today or now if ( field1.value.toUpperCase() == 'NOW' || field1.value.toUpperCase() == 'TODAY' ) { var newDate1 = new Date(); if (navigator.appName == "Netscape") { var myYear1 = newDate1.getYear() + 2000; } else { var myYear1 =newDate1.getYear(); } var myMonth1 = newDate1.getMonth()+1; var myDay1 = newDate1.getDate(); field1.value = myDay1 + "/" + myMonth1 + "/" + myYear1; fLength = field1.value.length;//re-evaluate string length. s = String(field1.value)//re-evaluate the string value. } //Check the date is the required length if ( fLength != 0 && (fLength < 6 || fLength > 11) ) { invalid_date(field1); return false; } // Find position and type of divider in the date for ( var i=0; i<3; i++ ) { for ( var x=0; x 12,. Author: Simon Kneafsey Date Created: 4/9/00 Email: simonkneafsey@hotmail.com WebSite: www.simonkneafsey.co.uk Notes: Please feel free to use/edit this script. If you do please keep my comments and details intact and notify me via a quick Email to the address above. Enjoy! *******************************************************************/ function validate_date(day2, month2, year2) { var DayArray = new Array(31,28,31,30,31,30,31,31,30,31,30,31); var MonthArray = new Array("01","02","03","04","05","06","07","08","09","10","11","12"); var inpDate = day2 + month2 + year2; var filter=/^[0-9]{2}[0-9]{2}[0-9]{4}$/; //Check ddmmyyyy date supplied if (! filter.test(inpDate)) { return false; } /* Check Valid Month */ filter=/01|02|03|04|05|06|07|08|09|10|11|12/ ; if (! filter.test(month2)) { return false; } /* Check For Leap Year */ var N = Number(year2); if ( ( N%4==0 && N%100 !=0 ) || ( N%400==0 ) ) { DayArray[1]=29; } /* Check for valid days for month */ for(var ctr=0; ctr<=11; ctr++) { if (MonthArray[ctr]==month2) { if (day2<= DayArray[ctr] && day2 >0 ) { inpDate = day2 + '/' + month2 + '/' + year2; return inpDate; } else { return false; } } } } /****************************************************************** validate_year() converts yy years to yyyy Uses a hinge date of 10 < 10 = 20yy => 10 = 19yy. Called by convert_date() before validate_date(). Author: Simon Kneafsey Date Created: 4/9/00 Email: simonkneafsey@hotmail.com WebSite: www.simonkneafsey.co.uk Notes: Please feel free to use/edit this script. If you do please keep my comments and details intact and notify me via a quick Email to the address above. Enjoy! *******************************************************************/ function validate_year(inYear) { if ( inYear < 10 ) { inYear = "20" + inYear; return inYear; } else if ( inYear >= 10 ) { inYear = "20" + inYear; return inYear; } else { return false; } }