tags:

views:

75

answers:

3

Hello,

I have an HTML text field. I want to validate via JavaScript that the value entered is a valid date in the form of "MM/DD/YY" or "MM/D/YY" or "MM/DD/YYYY" or "MM/D/YYYY". Is there a function that does this?

I sort of assumed there was something like isNaN but I don't see anything. Is it true that JavaScript can't validate dates?

A: 

Is it true that JavaScript can't validate dates?

No.

Is there a function that does this?

No.

You will need to write your own validation function to parse the date format (regex comes to mind) and then determine if it is valid within your specific criteria.

Jani Hartikainen
I like how this was downvoted even though I explicitly answered both of the questions and provided additional information :P
Jani Hartikainen
I like it too. Here's a +1 to offset all the -1's I've given today.
Justin Johnson
+1  A: 

Have you googled for something like javascript date validation? It shows up some good information, and a working code example here.

Bruno Reis
Sorry to be PITA, but if everyone was told to google it, there would be no need for this site. This site is for people to offer advice and code, not to just say google it!
Gary Willoughby
Did I *just* say google it? Can't you see I gave him (a link to) a code example?
Bruno Reis
Also, Gary, don't you agree that some *do* need to be told to google a bit?
Bruno Reis
A: 

If you want to venture into the realms of JQuery there are plenty of validation plugins that include date validation. This plugin is one I've used a few times and has served me well.

colethecoder