// Date Routine Check // Returns True or False function isValidDate(dateStr, DateName) { // Checks for the following valid date formats: // MM/DD/YY MM/DD/YYYY MM-DD-YY MM-DD-YYYY CHanged to YYYY/MM/DD or YYYY-MM-DD // Also separates date into month, day, and year variables // var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/; var datePat = /^(\d{1,4})(\/|-)(\d{1,2})\2(\d{2})$/; // To require a 4 digit year entry, use this line instead: // var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; var matchArray = dateStr.match(datePat); // is the format ok? if (matchArray == null) { alert(DateName + " is not in a valid format. Please re-enter the " + DateName + " in yyyy-mm-dd format.") return false; } month = matchArray[3]; // parse date into variables day = matchArray[4]; year = matchArray[1]; if (month < 1 || month > 12) { // check month range alert("Month must be between 1 and 12. Please re-enter the " + DateName + "."); return false; } if (day < 1 || day > 31) { alert("Day must be between 1 and 31. Please re-enter the " + DateName + "."); return false; } if ((month==4 || month==6 || month==9 || month==11) && day==31) { alert("Month "+month+" doesn't have 31 days! Please re-enter the " + DateName + ".") return false } if (month == 2) { // check for february 29th var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); if (day>29 || (day==29 && !isleap)) { alert("February " + year + " doesn't have " + day + " days! Please re-enter the " + DateName + "."); return false; } } return true; // date is valid } function isValidDateTime(dateStr, DateName) { // Checks for the following valid date formats: // YYYY/MM/DD HH:MM:SS or YYYY-MM-DD HH:MM:SS // Also separates date into month, day, and year variables var datePat = /^(\d{1,4})(\/|-)(\d{1,2})(\/|-)(\d{1,2})(\s)(\d{1,2})(\:)(\d{1,2})(\:)(\d{1,2})$/; var matchArray = dateStr.match(datePat); // is the format ok? if (matchArray == null) { alert(DateName + " is not in a valid format. Please re-enter the " + DateName + " in yyyy-mm-dd hh:mm:ss format.") return false; } month = matchArray[3]; // parse date into variables day = matchArray[4]; year = matchArray[1]; hour =matchArray[7]; minute = matchArray[9]; second= matchArray[11]; if (month < 1 || month > 12) { // check month range alert("Month must be between 1 and 12. Please re-enter the " + DateName + "."); return false; } if (day < 1 || day > 31) { alert("Day must be between 1 and 31. Please re-enter the " + DateName + "."); return false; } if ((month==4 || month==6 || month==9 || month==11) && day==31) { alert("Month "+month+" doesn't have 31 days! Please re-enter the " + DateName + ".") return false } if (month == 2) { // check for february 29th var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); if (day>29 || (day==29 && !isleap)) { alert("February " + year + " doesn't have " + day + " days! Please re-enter the " + DateName + "."); return false; } } if (hour < 0 || hour > 24) { // check hour range alert("Hour must be between 0 and 24. Please re-enter the " + DateName + "."); return false; } if (minute < 0 || minute > 60) { // check minute range alert("Minute must be between 0 and 60. Please re-enter the " + DateName + "."); return false; } if (second < 0 || second > 60) { // check second range alert("Second must be between 0 and 60. Please re-enter the " + DateName + "."); return false; } return true; // date is valid } function isValidTime(dateStr, DateName) { // Checks for the following valid date formats: // HH:MM:SS var datePat = /^(\d{1,2})(\:)(\d{1,2})(\:)(\d{1,2})$/; var matchArray = dateStr.match(datePat); // is the format ok? if (matchArray == null) { alert(DateName + " is not in a valid format. Please re-enter the " + DateName + " in hh:mm:ss format.") return false; } hour =matchArray[1]; minute = matchArray[3]; second= matchArray[5]; if (hour < 0 || hour > 24) { // check hour range alert("Hour must be between 0 and 24. Please re-enter the " + DateName + "."); return false; } if (minute < 0 || minute > 60) { // check minute range alert("Minute must be between 0 and 60. Please re-enter the " + DateName + "."); return false; } if (second < 0 || second > 60) { // check second range alert("Second must be between 0 and 60. Please re-enter the " + DateName + "."); return false; } return true; // time is valid } // Returns false if data entered is not numeric function NumericCheck(ControlValue){ var digits = "0123456789" for (var i=0;i 1) secondArg = isSignedInteger.arguments[1]; // skip leading + or - if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") ) startPos = 1; return (isInteger(s.substring(startPos, s.length), secondArg)) } } // Returns true if all characters in string s are numbers. // point, exponential notation, etc. function isInteger (s) { var i; if (isEmpty(s)) if (isInteger.arguments.length == 1) return defaultEmptyOK; else return (isInteger.arguments[1] == true); // Search through string's characters one by one // until we find a non-numeric character. // When we do, return false; if we don't, return true. for (i = 0; i < s.length; i++) { // Check that current character is number. var c = s.charAt(i); if (!isDigit(c)) return false; } // All characters are numbers. return true; }