View Full Version : JavaScript Date/Time Validation

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!

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;

04-14-2009, 11:39 AM
Please some help me to do auto format of the time field with below rules
1. Allows user to enter time of day as ‘A’ or ‘AM’, ‘P’ or ‘PM’
2. If user enters ‘N’ it will be converted to ‘PM’
3. Minutes must have 2 digits
4. 2 digit hour is not required
5. ‘:’ is not required as a separator between hours and minutes
6. Will only accept 12 hour times. E.g. will accept 1P, will not accept 1300
7. Upon field exit TAP will automatically display time in correct. Examples of possible time inputs –
8. User enters 3P and TAP will change to 3:00 PM.
9. User enters 120P and TAP will change to 1:20PM. If user intended time to be 12P they can see the time in the corrected format and can modify

Please help to implement the same, means for auto format