views:

34

answers:

2

Have a text input box.
Would like the user to enter a string in the exact format:

2010/08/26 17:04:51.24  

(with any numbers of course)

How can I do this efficiently?

Not looking for the answer, just a point in the right direction.

Thank You.

(html, JavaScript and jQuery)

+2  A: 

Regular expressions would be the most obvious solution. That being said, you probably don't want to go through the trouble of implementing a regular expression for matching dates and times when you can instead use an already existing solution.

DateJs is a really great JavaScript date parser that handles converting user-entered dates and times into meaningful values. DateJs can intelligently parse natural language expressions like "tomorrow" or "+5 days" and also standard date and time representations like "10/24/2008 11:31:04 AM".

Nathan Taylor
@Nathan Taylor: DateJs looks good but I put my string in and it didn't know what to do! I think regular expressions are the way to go.
Tommy
I think it's the ".24" at the end that it doesn't know how to handle. Is that significant?
Nathan Taylor
@Nathan Taylor:: yes....
Tommy
+1  A: 

I believe you'd want a regular expression to do this. I don't know of any other way to validate format other than that. I'm sure there are some libraries/plugins, but they probably just use a regular expression inside of them.

Edit: Nathan Taylor is right, DateJS is pretty great.

theIV