Mohamed Nizar Mohamed Nizar -4 years ago 203
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download