View Full Version : Input String Validation (Date format)

12-29-2005, 05:35 PM
Howdy all,

I have a textbox which prompts/requests (via an alert() mesasge) the user to enter a date using the mm/dd/yy format. Problem is, I can't seem to devise an approach to validate that the content they entered into this textbox is in a proper datetime format.

For example, the alert box pops onfocus stating "Please enter the date as MM/DD/YY", but the user can type in "peanut butter" and carry on. Or they can type in "122905". I'm looking for an approach that will check the content of the textbox (say onblur?) for an appropriate date format.

<input type="text" name="DateInJob" size="20" style="text-align:center" onfocus="alert('Enter Date as MM/DD/YYYY')">

I know I could use a popup calendar to prefill a date in this format, but in this case, if I can simply just validate the entry, it would make for the better user-experience. Reason being is that one of these such fields is the 'Date in Position' which could be any date from 1984 to current. I'd hate to have the user scroll through 21 years (*12 months) of a calendar just to 'find' the date when I can essentially just force them into typing the date in an acceptable format.

I appreciate any thoughts/concepts/etc.
Let me know if you have any questions.

- I

12-29-2005, 05:47 PM
Forget it - I found it...

WEBMASTER - You may delete this post.