/* FUNCTIONS AVAILABLE: function val_AdjustForY2K(val) { function field_Round(fld, intNumDecimalPlaces) { function datefield_AdjustForY2K(fld) { //NOTE: CALLED IN field_IsDateTime; SHOULD NOT BE NEED TO BE CALLED FROM ELSEWHERE: function ctl_ShowProblem(fld, strMsg) { function field_IsSelected (fld, strMsg) { function field_IsLongEnough (fld, intMinLength, strMsg) { function field_IsTooLong (fld, intMaxLength, strMsg) { function field_IsTooLongWTrunc(fld, intMaxLength, strFieldName, strMsg) { function val_IsInteger (strVal, strMinVal, strMaxVal) { function val_IsReal (strVal, strMinVal, strMaxVal) { function val_IsCurrency (strVal, strMinVal, strMaxVal) { function val_IsDateTime (strVal) { function field_IsInteger (fld, strMinVal, strMaxVal, strMsg) { function field_IsReal (fld, strMinVal, strMaxVal, strMsg) { function field_IsCurrency (fld, strMinVal, strMaxVal, strMsg) { function field_IsDateTime (fld, strMinVal, strMaxVal, strMsg) { function zOLD020328field_IsDateTime(fld, strMinVal, strMaxVal, strMsg) { function field_IsEmailAddress (fld, strMsg) { function field_IsUSZip (fld, strMsg) { function field_IsSSN (fld, strMsg){ function SSNField_StripDashes (fld) { function fieldset_IsValidDateRange(fldStartDate, fldEndDate, strMinVal, strMaxVal, strMsg) { function field_IsAlphanumericPLUS (fld, strAddlAllowedChars, strMsg){ function isLetter (c) function isDigit (c) function isLetterOrDigit (c) THE "field_Is..." FUNCTIONS ARE TO BE USED LIKE THIS: function form_onSubmit(frm) { if (!field_IsSelected(frm.lstFred, "Please select a Fred.")) { return false; } if (frm.hidCMD.value == "GO") { if (!field_IsLongEnough(frm.txtUsername, 4, "Please enter your username (at least 4 characters).")) return false; if (!field_IsLongEnough(frm.txtPassword, 6, "Please enter your password (at least 6 characters).")) return false; } return true; } (c) 1996-1997 Richard R. McQuillin. All Rights Reserved. History: 1. 1996+ circa. RMcQ. Created & upgraded originally for CostBuster, CORE, etc. 2. 00-12-18 RMcQ. Revised to pass in field (control) instead of value; allows this proc to set focus to the control and select the contents. 3. 01-10-23 RMcQ. Improved number handlers. NOTE: OPTIONAL ARGUMENTS: To specify a value for an optional field, enter a non-zero length string (i.e., passing a zero-length string means the optional value is NOT being passed in). NOTE: COMMON ARGUMENTS: The following comments apply to the standard input arguments of all "field_Is" functions: Arguments: fld - the field (HTML control containing data) to be tested. strMsg - (optional) a message that will be displayed if the function returns false. strMinVal - (optional) a minimum value which the field value must be greater than or equal to. strMaxVal - (optional) a maximum value which the field value must be less than or equal to. Some procs adapted from from JavaScript Sourcebook (c) 1996 Gordon McComb p. 482. */ function val_AdjustForY2K(val) { //01-04-07 RMcQ //NOTE: Needed when the date value to be adjusted is not in a control; //e.g. it is returned from a Javascript prompt var dt = new Date(val); if (dt.getFullYear() < 1950) { dt.setFullYear(dt.getFullYear() + 100); } var dtAdjusted = (dt.getMonth() + 1) + '/' + dt.getDate() + '/' + dt.getFullYear(); return dtAdjusted; } function field_Round(fld, intNumDecimalPlaces) { //01-04-10 RMcQ fld.value = parseInt(fld.value * Math.pow(10, intNumDecimalPlaces)) / (Math.pow(10, intNumDecimalPlaces)) } function datefield_AdjustForY2K(fld) { //01-04-07 RMcQ //NOTE: CALLED IN field_IsDateTime; SHOULD NOT BE NEED TO BE CALLED FROM ELSEWHERE: var dt = new Date(fld.value); // alert('dt.getYear = ' + dt.getYear() + '; dt.getFullYear=' + dt.getFullYear()); if (dt.getFullYear() < 1900) { dt.setFullYear(dt.getFullYear() + 100); } fld.value = (dt.getMonth() + 1) + '/' + dt.getDate() + '/' + dt.getFullYear(); } function ctl_ShowProblem(fld, strMsg) { //00-12-18 RMcQ //This is meant to be if (strMsg.length > 0) alert(strMsg); else alert("Please provide a valid entry for this field.") fld.focus(); if (fld.type != "select-one") { fld.select() }; } function field_IsSelected(fld, strMsg) { //11/1/97 RMcQ //For select-type HTML input controls //returns a boolean value indicating whether or not the field is selected. //See also file-level comments above. //ASSUMES that the field's value is "-Select-" if unselected. if ((select_GetVal(fld) == "-Select-") || (select_GetVal(fld) == "-Add New-")) { if (strMsg.length > 0) alert(strMsg); else alert("Please provide a valid entry for this field.") fld.focus(); return false; } return true; } function field_IsLongEnough(fld, intMinLength, strMsg) { //11/1/97 RMcQ //Improved (generalized) from "field_IsEmpty". //returns a boolean value indicating whether or not a field is empty. //See also file-level comments above. //Pass in 1 for intMinLength to assure that the field is not empty. // debug_Alert(m_intDebugValidations, "fld.value=" + fld.value + ", fld.value.length=" + fld.value.length); if (intMinLength == 0) intMinLength = 1; //just in case client passes in "0" for intMinLength if (fld.value.length < intMinLength) { ctl_ShowProblem(fld, strMsg); return false; } return true; } function field_IsTooLong(fld, intMaxLength, strMsg) { //01-12-07 RMcQ //Adapted from "field_IsLongEnough". //Returns a boolean value indicating whether or not a field is too long. //NOTE: MOST USEFUL for "textarea" fields, which don't limit to maxlength. //See also file-level comments above. //Pass in what would be a text control's "maxsize" for intMaxLength. // debug_Alert(m_intDebugValidations, "fld.value=" + fld.value + ", fld.value.length=" + fld.value.length); if (fld.value.length > intMaxLength) { strMsg = strMsg + "\n\nThe current length is " + fld.value.length + " characters." ctl_ShowProblem(fld, strMsg); return true; } return false; } function field_IsTooLongWTrunc(fld, intMaxLength, strFieldName, strMsg) { //03-02-10 RMcQ //Checks if the field is too long, but offers to truncate it if it is. var intExcessCount intExcessCount = fld.value.length - intMaxLength if (intExcessCount > 0) { var strFinalMsg if (strMsg == "") strFinalMsg = "Your '" + strFieldName + "' entry has " + intExcessCount + " excess characters and will be shortened. Press OK to continue or Cancel to edit the value." else strFinalMsg = strMsg if (!confirm(strFinalMsg)) { fld.select(); fld.focus(); return false; } } return true; } function val_IsInteger(strVal, strMinVal, strMaxVal) { //03-02-16 RMcQ //Returns a boolean value indicating whether or not "strVal" contains an integer number value. //See also file-level comments above. //NOTE: Not perfect, it removes ALL commas, so a number like 1,2,3,4 would become 1234. if (strVal == "") return false; if (isNaN(strVal)) return false; var strValWNoCommas = strVal.replace(',', '') if (parseInt(strValWNoCommas) != strValWNoCommas) return false; if (strMinVal.length > 0) { if (parseInt(strValWNoCommas) < parseInt(strMinVal)) return false; } if (strMaxVal.length > 0) { if (parseInt(strValWNoCommas) > parseInt(strMaxVal)) return false; } return true; } function val_IsReal(strVal, strMinVal, strMaxVal) { //03-02-16 RMcQ //Returns a boolean value indicating whether or not "strVal" contains a real number value. //See also file-level comments above. //NOTE: Not perfect, it removes ALL commas, so a number like 1,2,3,4 would become 1234. if (strVal == "") return false; if (isNaN(strVal)) return false; var strValWNoCommas = strVal.replace(',', '') if (parseFloat(strValWNoCommas) != strValWNoCommas) return false; if (strMinVal.length > 0) { if (parseFloat(strValWNoCommas) < parseFloat(strMinVal)) return false; } if (strMaxVal.length > 0) { if (parseFloat(strValWNoCommas) > parseFloat(strMaxVal)) return false; } return true; } function val_IsCurrency(strVal, strMinVal, strMaxVal) { //03-02-16 RMcQ //Returns a boolean value indicating whether or not "strVal" contains a currency value. //See also file-level comments above. //NOTE that this just checks for a "$", then calls "val_IsReal" if (strVal == "") return false; //If strVal starts with a '$', STRIP it, then continue: if ((strVal.length > 1) && (strVal.substr(0,1) == '$')) { strVal = strVal.substr(1); } return val_IsReal(strVal, strMinVal, strMaxVal); } function val_IsDateTime(strVal, fld) { //02-05-03 RMcQ //returns a boolean value indicating whether or the string value strVal is a date. //if calling from a field, pass the field object in using the fld arg. Otherwise, leave this empty (undefined). if (strVal == "") return false; if (isNaN(Date.parse(strVal))) return false; if (!chkdate(strVal, fld)) return false; return true; } function field_IsInteger(fld, strMinVal, strMaxVal, strMsg) { //11/1/97 RMcQ //returns a boolean value indicating whether or not a field contains an integer value. //See also file-level comments above. //NOTE: Not perfect, it removes ALL commas, so a number like 1,2,3,4 would become 1234. //IMPROVE: to just call val_IsInt //Load the default message if no message is provided: if (strMsg == '') strMsg = 'Please enter a whole number (1, 2, 3, etc.)'; if (!field_IsLongEnough(fld, 1, strMsg)) return false; var strFldValWNoCommas = fld.value.replace(',', '') //First test that the string contains an integer: if (parseInt(strFldValWNoCommas) != strFldValWNoCommas) { ctl_ShowProblem(fld, strMsg); return false; } //Next, test that the input string is greater than the min val if one is provided: if (strMinVal.length > 0) { if (parseInt(strFldValWNoCommas) < parseInt(strMinVal)) { ctl_ShowProblem(fld, strMsg); return false; } } //Next, test that the input string is less than the max val if one is provided: if (strMaxVal.length > 0) { if (parseInt(strFldValWNoCommas) > parseInt(strMaxVal)) { ctl_ShowProblem(fld, strMsg); return false; } } return true; } function field_IsReal(fld, strMinVal, strMaxVal, strMsg) { //11/1/97 RMcQ //returns a boolean value indicating whether or not a field contains a real number value. //See also file-level comments above. //NOTE: Not perfect, it removes ALL commas, so a number like 1,2,3,4 would become 1234. //IMPROVE: to just call val_IsReal //Load the default message if no message is provided: if (strMsg == '') strMsg = 'Please enter a real number.'; if (!field_IsLongEnough(fld, 1, strMsg)) return false; var strFldValWNoCommas = fld.value.replace(',', '') //First test that the string contains a real number: if (parseFloat(strFldValWNoCommas) != strFldValWNoCommas) { ctl_ShowProblem(fld, strMsg); return false; } //Next, test that the input string is greater than the min val if one is provided: if (strMinVal.length > 0) { if (parseFloat(strFldValWNoCommas) < parseFloat(strMinVal)) { ctl_ShowProblem(fld, strMsg); return false; } } //Next, test that the input string is less than the max val if one is provided: if (strMaxVal.length > 0) { if (parseFloat(strFldValWNoCommas) > parseFloat(strMaxVal)) { ctl_ShowProblem(fld, strMsg); return false; } } return true; } function field_IsCurrency(fld, strMinVal, strMaxVal, strMsg) { //01-12-11 RMcQ //returns a boolean value indicating whether or not a field contains a valid currency value. //See also file-level comments above. //NOTE that this just checks for a "$", then calls "field_IsReal" //NOTE: THE _OLD_ field_IsCurrency code was removed on 02-01-15: //IMPROVE: to just call val_IsCurrency //Load the default message if no message is provided: if (strMsg == '') strMsg = 'Please enter a currency value.'; //If the field starts with a '$', STRIP it, then continue: if ((fld.value.length > 1) && (fld.value.substr(0,1) == '$')) { fld.value = fld.value.substr(1); } return field_IsReal(fld, strMinVal, strMaxVal, strMsg); } function field_IsDateTime(fld, strMinVal, strMaxVal, strMsg) { //11/1/97 RMcQ, rev 01-04-10 RMcQ to include call to "datefield_AdjustForY2K", rev 02-03-28 //returns a boolean value indicating whether or not a field contains a date value. //See also file-level comments above. // if (!field_IsLongEnough(fld, 1, strMsg)) return false; // // if (isNaN(Date.parse(fld.value))) { // ctl_ShowProblem(fld, strMsg); // return false; // } // if (!chkdate(fld.value, fld)) { // ctl_ShowProblem(fld, strMsg); // return false; // } //02-05-03 RMcQ replaced with this: if (!val_IsDateTime(fld.value, fld)) { ctl_ShowProblem(fld, strMsg); return false; } var datTest = new Date(fld.value); var datMin = new Date(strMinVal); var datMax = new Date(strMaxVal); //Next, test that the input string is greater than the min val if one is provided: if (strMinVal.length > 0) { if (datTest < datMin) { ctl_ShowProblem(fld, strMsg); return false; } } //Next, test that the input string is less than the max val if one is provided: if (strMaxVal.length > 0) { if (datTest > datMax) { ctl_ShowProblem(fld, strMsg); return false; } } return true; } function zOLD020328field_IsDateTime(fld, strMinVal, strMaxVal, strMsg) { //11/1/97 RMcQ, rev 01-04-10 RMcQ to include call to "datefield_AdjustForY2K" //returns a boolean value indicating whether or not a field contains a date value. //See also file-level comments above. // alert("In field_IsDateTime"); // datefield_AdjustForY2K(fld); REMOVED 02-03-05 RMcQ chkdate(fld.value, fld); //PERFORMED HERE JUST TO ADJUST THE DATE IN THE FIELD BEFORE CONTINUING //(also performed below to actually do the test) var datTest = new Date(fld.value); var datMin = new Date(strMinVal); var datMax = new Date(strMaxVal); //First test that the string contains a valid date: //This "experimental" test does work: If the date is invalid, "parse" will return 0: if (!field_IsLongEnough(fld, 1, strMsg)) return false; // if (!(Date.parse(fld.value) > 0)) { // ctl_ShowProblem(fld, strMsg); // return false; // } //REPLACED WITH THIS: if (isNaN(Date.parse(fld.value))) { ctl_ShowProblem(fld, strMsg); return false; } if (!chkdate(fld.value, fld)) { ctl_ShowProblem(fld, strMsg); return false; } //Next, test that the input string is greater than the min val if one is provided: if (strMinVal.length > 0) { // debug_Alert(m_intDebugValidations, "datTest=" + datTest + ". datMin=" + datMin); if (datTest < datMin) { ctl_ShowProblem(fld, strMsg); return false; } } //Next, test that the input string is less than the max val if one is provided: if (strMaxVal.length > 0) { if (datTest > datMax) { ctl_ShowProblem(fld, strMsg); return false; } } return true; } function field_IsEmailAddress(fld, strMsg) { //01-10-23 RMcQ //01-10-23 RMcQ Obtained from ask.com on the public internet. //Adapted from a proc called "validEmail": // This script copyright 1997, Tom Negrino and Dori Smith. // This script is from "JavaScript for the WWW, Visual QuickStart Guide, 2nd Ed." // For more information, see . // This script may be used and modified, but the copyright notice must remain intact. if (fld.value == "") { ctl_ShowProblem(fld, strMsg); return false; } var invalidChars = " /:,;" for (var i=0; i < invalidChars.length; i++) { var badChar = invalidChars.charAt(i) if (fld.value.indexOf (badChar,0) != -1) { ctl_ShowProblem(fld, strMsg); return false; } } var atPos = fld.value.indexOf ("@",1); if (atPos == -1) { ctl_ShowProblem(fld, strMsg); return false; } if ( fld.value.indexOf ("@", atPos+1) != -1) { ctl_ShowProblem(fld, strMsg); return false; } periodPos = fld.value.indexOf (".", atPos); if ( periodPos == -1) { ctl_ShowProblem(fld, strMsg); return false; } if ( periodPos+3 > fld.value.length) { ctl_ShowProblem(fld, strMsg); return false; } return true; } function field_IsUSZip (fld, strMsg) { //11/1/97 RMcQ, improved 01-10-23 RMcQ //returns a boolean value indicating whether or not a field contains a US Zip code. //See also file-level comments above. //Load the default message if no message is provided: if (strMsg == '') strMsg = 'Please enter valid 5-digit or 9-digit U.S. zip code (e.g. \'12345\' or \'12345-6789\').'; //check to see if the value is long enough: if (!field_IsLongEnough(fld, 1, strMsg)) return false; //assure the zip code is either 5 or 10 digits long: if ((fld.value.length!=5) && (fld.value.length!=10)) { ctl_ShowProblem(fld, strMsg); return false; } var i; var strRef="1234567890"; //check that the first five digits are correct: var strPrefix = fld.value.substring(0,5) //alert('strPrefix=' + strPrefix); for (var i=0; i < strPrefix.length; i++ ) { TempChar= strPrefix.substring (i, i+1); if (strRef.indexOf (TempChar, 0)==-1) { ctl_ShowProblem(fld, strMsg); return false; } } if (fld.value.length == 10) { //then a 9-digit zip code is being provided //check that the dash is correct: var strDash = fld.value.substring(5,6) //alert('strDash=' + strDash); if (strDash != "-") { ctl_ShowProblem(fld, strMsg); return false; } //check that the last four digits are correct: var strSuffix = fld.value.substring(6,10) //alert('strSuffix=' + strSuffix); for ( i=0; i < strSuffix.length; i++ ) { TempChar= strSuffix.substring (i, i+1); if (strRef.indexOf (TempChar, 0)==-1) { ctl_ShowProblem(fld, strMsg); return false; } } } return true; } function field_IsSSN(fld, strMsg){ //1/27/99 RMcQ //returns a boolean value indicating whether or not a field contains //a valid US Social Security Number (SSN) in the format "nnn-nn-nnnn" //where n is a digit (0 to 9). //See also file-level comments above. //Adapted from the "field_lengthType" created by Gautam Sharma on 12/30/98 //NOTE: This proc uses the SSNField_StripDashes proc. if (!field_IsLongEnough(fld, 1, strMsg)) return false; if ((fld.value.length == 9) || ((fld.value.length == 11) && ((fld.value.indexOf('-',0) == 3) & (fld.value.indexOf('-',4) == 6)))) { //the "mask" of the number is valid; so check that all values are digits: var strSSNWithoutDashes = SSNField_StripDashes(fld) var varStrRef = "1234567890"; for (var i = 0; i < strSSNWithoutDashes.length; i++ ) { var charTemp = strSSNWithoutDashes.substring(i,i+1); if (varStrRef.indexOf(charTemp, 0) == -1) { ctl_ShowProblem(fld, strMsg); return false; } } return true; } else { //this is neither a 9-digit nor an 11-digit string, so it can't be an SSN: ctl_ShowProblem(fld, strMsg); return false; } } function SSNField_StripDashes(fld) { //1/15/99 RMcQ //Given an SSN, returns the field without dashes. // alert (fld.value); if (fld.value.length == 11) { //Assume the SSN is in a valid format containing dashes, //such as "nnn-nn-nnnn", so strip the dashes: return fld.value.substring( 0, 3) + fld.value.substring( 4, 6) + fld.value.substring( 7, 11); } else { return fld.value; } } function fieldset_IsValidDateRange(fldStartDate, fldEndDate, strMinVal, strMaxVal, strMsg) { //02-02-25 RMcQ //NOTE: strMsg input arg currently not used. if (!field_IsDateTime(fldStartDate, strMinVal, strMaxVal, "Please enter a valid start date.")) return false; if (!field_IsDateTime(fldEndDate, strMinVal, strMaxVal, "Please enter a valid end date.")) return false; if (Date.parse(fldStartDate.value) > Date.parse(fldEndDate.value)) { alert("Please enter an end date later than your start date."); fldEndDate.select(); fldEndDate.focus(); return false; } return true; } function field_IsAlphanumericPLUS (fld, strAddlAllowedChars, strMsg){ //02-09-21 RMcQ Modified from isAlphanumeric in FormChek.js //Returns true if string s is English letters //(A .. Z, a..z) and numbers only. // //Load the default message if no message is provided: if (strMsg == '') strMsg = 'Please enter an alphanumeric value only.'; var i; // Search through string's characters one by one // until we find a non-alphanumeric character. // When we do, return false; if we don't, return true. for (i = 0; i < fld.value.length; i++) { // Check that current character is number or letter. var c = fld.value.charAt(i); if ( !isLetterOrDigit(c) && (strAddlAllowedChars.search(c) == -1) ) { ctl_ShowProblem(fld, strMsg); return false; return false; } } // All characters are numbers or letters. return true; } //02-09-22 RMcQ: SUPPORT FUNCTIONS FOR field_IsAlphanumeric //COPIED IN FROM FormChek.js // Returns true if character c is an English letter // (A .. Z, a..z). // // NOTE: Need i18n version to support European characters. // This could be tricky due to different character // sets and orderings for various languages and platforms. function isLetter (c) { return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) ) } // Returns true if character c is a digit // (0 .. 9). function isDigit (c) { return ((c >= "0") && (c <= "9")) } // Returns true if character c is a letter or digit. function isLetterOrDigit (c) { return (isLetter(c) || isDigit(c)) } //START CODE TAKEN FROM javascriptsource.com ********************************************** //02-05-03 RMcQ modified to take a date as first input arg, not a field. //BUT fldDat is taken as a second arg function chkdate(datIn, fldDat) { var strDatestyle = "US"; //United States date style //var strDatestyle = "EU"; //European date style var strDate; var strDateArray; var strDay; var strMonth; var strYear; var intday; var intMonth; var intYear; var booFound = false; var strSeparatorArray = new Array("-"," ","/","."); var intElementNr; var err = 0; var strMonthArray = new Array(12); strMonthArray[0] = "Jan"; strMonthArray[1] = "Feb"; strMonthArray[2] = "Mar"; strMonthArray[3] = "Apr"; strMonthArray[4] = "May"; strMonthArray[5] = "Jun"; strMonthArray[6] = "Jul"; strMonthArray[7] = "Aug"; strMonthArray[8] = "Sep"; strMonthArray[9] = "Oct"; strMonthArray[10] = "Nov"; strMonthArray[11] = "Dec"; strDate = datIn; if (strDate.length < 1) { return true; } for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) { if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) { strDateArray = strDate.split(strSeparatorArray[intElementNr]); if (strDateArray.length != 3) { err = 1; return false; } else { strDay = strDateArray[0]; strMonth = strDateArray[1]; strYear = strDateArray[2]; } booFound = true; } } if (booFound == false) { if (strDate.length>5) { strDay = strDate.substr(0, 2); strMonth = strDate.substr(2, 2); strYear = strDate.substr(4); } } if (strYear.length == 2) { strYear = '20' + strYear; } // US style if (strDatestyle == "US") { strTemp = strDay; strDay = strMonth; strMonth = strTemp; } intday = parseInt(strDay, 10); if (isNaN(intday)) { err = 2; return false; } intMonth = parseInt(strMonth, 10); if (isNaN(intMonth)) { for (i = 0;i<12;i++) { if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) { intMonth = i+1; strMonth = strMonthArray[i]; i = 12; } } if (isNaN(intMonth)) { err = 3; return false; } } intYear = parseInt(strYear, 10); if (isNaN(intYear)) { err = 4; return false; } if (intMonth>12 || intMonth<1) { err = 5; return false; } if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) { err = 6; return false; } if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) { err = 7; return false; } if (intMonth == 2) { if (intday < 1) { err = 8; return false; } if (LeapYear(intYear) == true) { if (intday > 29) { err = 9; return false; } } else { if (intday > 28) { err = 10; return false; } } } if (strDatestyle == "US") { if (fldDat != undefined) { fldDat.value = strMonthArray[intMonth-1] + " " + intday + " " + strYear; } } else { if (fldDat != undefined) { fldDat.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear; } } return true; } function LeapYear(intYear) { if (intYear % 100 == 0) { if (intYear % 400 == 0) { return true; } } else { if ((intYear % 4) == 0) { return true; } } return false; } function doDateCheck(from, to) { if (Date.parse(from.value) <= Date.parse(to.value)) { alert("The dates are valid."); } else { if (from.value == "" || to.value == "") alert("Both dates must be entered."); else alert("To date must occur after the from date."); } } //END CODE TAKEN FROM javascriptsource.com **********************************************