0

I want to know whether the given string is datetime, so i used the Date.parse() method as below

var dateType=!isNaN(Date.parse("2/3/2012")) // return true;

but for the string "2000" i am getting dateType as true

var dateType=!isNaN(Date.parse("2000")) // return true;

i want to return true when the format like "mm/dd/yyyy" is used in string not for "2000", is there any method to to like this.

Thanks in advance

user3326265
  • 257
  • 1
  • 4
  • 14
  • Not sure about `Date.parse()`... [___This is an alternative___](http://stackoverflow.com/a/2587398/2260614) – Bhavik Jul 03 '14 at 07:21

1 Answers1

0

Try using Regular expression to validate.

for mm/dd/yyyy format use the below regex

 var date_regex = /^(0[1-9]|1[0-2])\/(0[1-9]|1\d|2\d|3[01])\/(19|20)\d{2}$/ ;

and you could test using

date_regex.test("11/09/2011")

also there are many other ways to do it. explore them also

practice2perfect
  • 499
  • 1
  • 4
  • 19