Jump to content

Archived

This topic is now archived and is closed to further replies.

Moron

Script to validate both date and time formats?

Recommended Posts

In my search for this, I've found scripts that will validate [i]either[/i] date or time input formats, but not both in the same script.

Anybody seen one like this?

Share this post


Link to post
Share on other sites
Users like to enter dates in so many different formats that I've always found the best solution to date/time entry is to give them a 'date picker' that places their selection into a text box on the form.  If they then decide to fool around with what's in the text box, they get what they deserve.  Meanwhile, users with IQs higher than room temperature will appreciate the ease of data entry provided by a date picker.

http://www.rainforestnet.com/datetimepicker.htm is excellent

Share this post


Link to post
Share on other sites
[quote author=AndyB link=topic=107380.msg430977#msg430977 date=1157758553]
Users like to enter dates in so many different formats that I've always found the best solution to date/time entry is to give them a 'date picker' that places their selection into a text box on the form.  If they then decide to fool around with what's in the text box, they get what they deserve.  Meanwhile, users with IQs higher than room temperature will appreciate the ease of data entry provided by a date picker.

http://www.rainforestnet.com/datetimepicker.htm is excellent
[/quote]

I'm already using a popup calendar date picker. It works great, but as you implied, it's just a matter of time before someone decides to enter it "manually" and gets it wrong. Right now there is NO validation on these fields except that they can't be left blank. You can enter anything, even a string like askdnvioweh as the date and it'll go as long as it's not blank.

Share this post


Link to post
Share on other sites
[quote author=AndyB link=topic=107380.msg431060#msg431060 date=1157772385]
Is server-side validation an option?
[/quote]

Possibly, but I somehow thought that I could find the perfect Javascript for this in a matter of seconds.

;D

Share this post


Link to post
Share on other sites
Bump.

Anybody seen a script like this? I'm finding everything BUT what I'm looking for.

Some calculate date differences. Don't need that.

Some allow standard or military time. Don't need military.

Some validate everything under the sun INCLUDING what I'm looking for, but crash if I try to modify them.

All I need is:

[b]Start Date:[/b] Must be mm/dd/yyyy format.
[b]Start Time:[/b] Must be hh:mm format. No military time, no GMT, no AM/PM.
[b]End Date:[/b] Must be mm/dd/yyyy format.
[b]End Time:[/b] Must be hh:mm format. No military time, no GMT, no AM/PM.
[b]Total Hours:[/b] Can't be left blank.

Anybody seen something similar without a bazillion features I don't need?

Share this post


Link to post
Share on other sites
I use a date picker also and they way I keep users from manipulating it is take make the INPUT field read only. Like this:

[code]<INPUT id="date" style="WIDTH: 75px" type="text" name="date" value="" title="Year-Month-Day Format." readOnly>[/code]

The date picker drops the selected value right in the box, but the user cannot make a change to it.

Share this post


Link to post
Share on other sites
You can be lazy and use a simple regular expression to get the formatting right, though you'll have to validate the "date" as a date too (i.e. try and make a JS Date object from the component pieces).

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.