PDA

View Full Version : JavaScript Date/Time Validation




guidosarducci
02-08-2006, 08:22 PM
Hello List -

I am some what of a new JavaScript user. I am trying to build a validation script that checks to make sure a date selected is: 1.) not past the current server date and 2.) if it is the current date, returns false if server time is > then 11:00AM.

This would be part of my onSubmit function for validations of form fields. I have a Java calendar already so the date is entered into a single field as mm/dd/yyyy.

Thank you for your help!

Twey
02-08-2006, 08:26 PM
String.prototype.isDate = function() { return isNaN(Date.parse(this)); }
function checkDate(date) {
var d;
if(Date.parse(date) < (d = new Date()).getTime() || !date.isDate() || (date == d && d.getHours() < 11)) return false;
return true;
}