Hi Folks,
I'm brand spankin' new to developing but was assigned a web app to develop in ASP.NET 4 with C#.
I am using JavaScript for validation. The problem I'm having is that the date validation alert box that pops up displays a lot of unneccesary time and timezone information, making it hard for the enduser to read.
How can I format the alert message (which is based on variables) to be more readable?
What I want: Date must be between Sun Sep 30 and Sat Oct 13
INSTEAD of THIS: Date must be between Sun Sep 30 00:00:00 PDT 2012 and Sat Oct 13 00:00:00 PDT 2012
Below is my code which falls within the $("form").validate(); code block...
//Date logic for Pay Period Ending/WorkDate triggered by the .datepickerCompleted function.
// selectedPPE is a DateTime variable which holds a date value chosen by the user from a dropbox control.
// Event: .datepicker completes. Create new Date variables:
$('.datepickerCompleted').change(function () {
var endDate = new Date('<%=selectedPPE%>');
var startDate = new Date('<%=selectedPPE%>');
// subtract 13 days to get beginning of payroll period:
startDate.setDate(startDate.getDate() - 13);
var enteredDate = $('.hasDatepicker').val();
// Compare user input to make sure the enteredDate is between startDate and endDate:
if ((Date.parse(enteredDate) >= Date.parse(startDate) && Date.parse(enteredDate) <= Date.parse(endDate)) == false)
alert("Date must be between " + startDate + " and " + endDate);
else {
alert("Date within range");
}
});