Click to See Complete Forum and Search --> : DateTime Validation


jskeens
12-30-2002, 02:33 PM
I was wondering if anyone could tell me what the pattern in javascript would be for DateTime Validation, I am new to Javascript and need some help. I have written a pattern out is this correct?

Example: MM/DD/YYYY HH:MM:SS AM/PM

/^\d{1,2}\/\d{1,2}\/\d{4} \d{2}:\d{2}:\d{2}$/;
:confused:

jskeens
12-31-2002, 06:57 AM
Thank you very much!:p

Charles
12-31-2002, 07:50 AM
Though, you might find that you really don't need to validate your date. someDate = new Date('some date') does an excellent job of understanding many different date formats. It recovers from invalid dates by understanding 32 December 2002 as 1 January 2003, which is not a bad way to treat errorious user input. And it's quite easy to re-format the date to your liking:

<script type="text/javascript">
<!--
Date.prototype.toString = function () {return [['Sunday,', 'Monday,', 'Tuesday,', 'Wednesday,', 'Thursday,', 'Friday,', 'Saturday,'] [this.getDay()], this.getDate(), ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] [this.getMonth()], this.getFullYear()].join(' ')}

alert(new Date('12-32-2002'));
// -->
</script>