Jump to content


Photo

Script to validate both date and time formats?


  • Please log in to reply
7 replies to this topic

#1 Moron

Moron
  • Members
  • PipPipPip
  • Advanced Member
  • 368 posts

Posted 08 September 2006 - 06:39 PM

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

Anybody seen one like this?



#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 08 September 2006 - 11:35 PM

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.rainfores...etimepicker.htm is excellent
Legend has it that reading the manual never killed anyone.
My site

#3 Moron

Moron
  • Members
  • PipPipPip
  • Advanced Member
  • 368 posts

Posted 09 September 2006 - 03:18 AM

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.rainfores...etimepicker.htm is excellent


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.



#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 09 September 2006 - 03:26 AM

Is server-side validation an option?
Legend has it that reading the manual never killed anyone.
My site

#5 Moron

Moron
  • Members
  • PipPipPip
  • Advanced Member
  • 368 posts

Posted 09 September 2006 - 03:31 AM

Is server-side validation an option?


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

;D

#6 Moron

Moron
  • Members
  • PipPipPip
  • Advanced Member
  • 368 posts

Posted 11 September 2006 - 04:59 PM

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:

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

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


#7 freakus_maximus

freakus_maximus
  • Members
  • PipPipPip
  • Advanced Member
  • 177 posts

Posted 13 September 2006 - 02:46 PM

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:

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

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

#8 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 20 September 2006 - 01:31 PM

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).
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users