MorganGreylock
Programmer
I've got a date field that is completely optional for the user. If they DO enter a date, I want to make sure that 1) it is a valid date in the form mm/dd/yyyy and 2) that it is not in the past. (Today is ok, yesterday is not).
Checking for 2) is okay, I've got that part finished. The problem I'm having is with 1), where I'm using isNaN() to see if its a valid date, but if the user leaves the (optional) field blank, it complains that its not a valid number. Here's my code:
Obviously there is a part missing, but I'm not sure what to add. Adding a check for && item.length > 0 doesn't work either. Any suggestions?
Thanks in advance
Checking for 2) is okay, I've got that part finished. The problem I'm having is with 1), where I'm using isNaN() to see if its a valid date, but if the user leaves the (optional) field blank, it complains that its not a valid number. Here's my code:
Code:
if (isNaN(str)){
alert('That is not a valid date.');
document.srdetails.date_needby.value = '';
return false;
}
Obviously there is a part missing, but I'm not sure what to add. Adding a check for && item.length > 0 doesn't work either. Any suggestions?
Thanks in advance