Mohamed Nizar Mohamed Nizar - 2 months ago 7x
Javascript Question

Check isDate is returning Invalid date

I have date string like this

1 May 2010 To 15 Aug 2016
.I just want to check this as date string on my function and not to proceed on a function.When I'm checking this string with
new Date(value)
its returning Invalid date.How can I check this as date?


I would use js date library moment js for this.

var checkDate = function (str){
  var dates = str.split("To");
  var flag = true;
  for(var i = 0; i < dates.length; i++) {
      if (moment(dates[i]).isValid()) {
        flag = false;

  return flag;

I have created a fiddle for that