Date Validation Bug Assistance
Hi,
I've searched the forums "date validation" topics but haven't seen this particular issue discussed. Sorry in advance if it's redundant.
I have two fields: "Month Ended" and Due_Date." Month Ended is user input with "date validation." Due_Date is calculated based on the user input in Month Ended.
The format for Month Ended and Due_Date is set to validate for mm/dd/yyyy.
Here are three scenarios and results:
1. User enters 9/30/2016. Due Date updates to 10/31/2016.
2. User enters 9/30/16. Validation script catches and prompts them to re-enter.
3. User enters 9/30. Month Ended "auto-corrects" to 9/30/2016 on the screen. But then Due Date adjusts to 01/00/0000.
Scenario 3 is what I need help resolving.
Below is the code in each text box.
MONTH ENDED DATE VALIDATION BOX (Note: This is also in the Date Validation box for Due_Date)
// Validates that the input string is a valid date formatted as "mm/dd/yyyy"
function isValidDate(dateString)
{
//first check for the pattern
if(!/^\d{1,2}\/\d{1,2}\/\d{4}$/.test(dateString))
return false;
//parse the date parts to integers
var parts = dateString.split("/");
var day = parseInt(parts[1], 10);
var month = parseInt(parts[0], 10);
var year = parseInt(parts[2], 10);
//check the ranges of month and year
if(year < 1000 || year > 3000 || month == 0 || month > 12)
return false;
var monthLength = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
//adjust for leap years
if(year % 400 == 0 || (year % 100 != 0 && year % 4 == 0))
monthLength[1] = 29;
//check the range of the day
return day > 0 && day <= monthLength[month - 1];
};
DUE_DATE CUSTOM CALCULATION SCRIPT BOX
//set variables and populate
var monthEnded = new Date(this.getField("Month Ended").value);
var currentYear = monthEnded.getFullYear();
var currentMonth = monthEnded.getMonth();
var lastDayofNextMonth = new Date(currentYear, currentMonth+2, 0);
event.value = util.printd("mm/dd/yyyy", lastDayofNextMonth);
