function checkInvalidDate(value, format, minDate, maxDate) {
  const date = moment(value, format, true);
  const isValidDate = date.isValid();

  if (!isValidDate) {
    const delimeters = value.match(/[^a-z0-9_]/gi);
    const delimetersRegEx = new RegExp(delimeters.join('|'), 'gi');

    const inputParts = value.replace(/_*/gi, '').split(delimetersRegEx);
    const formatParts = format[1] ? format[1].split(delimetersRegEx) : format[0].split(delimetersRegEx);

    const timeIndex = _.findIndex(formatParts, (part, index) => part.length === 1 && index === formatParts.length - 1);
    const yearIndex = _.findIndex(formatParts, part => part.match(/yyyy/gi));

    if (inputParts[yearIndex]/ 1000 < 1) {
      return buildResponse(CALENDAR_ERROR_MESSAGES.INVALID, false);
    }

    if (inputParts[0].length === formatParts[0].length) {
      const modifiedParts = inputParts.map((part, index) => {
        let partValue = part;
        if (!part && index === timeIndex) {
          partValue = 'AM';
        }
        else if (!part) {
          partValue = '01';
        }
        if (delimeters[index]) {
          partValue = `${partValue}${delimeters[index]}`;
        }

        return partValue;
      });

      const problemDate = moment(modifiedParts.join(''), format, true);

      if (problemDate.isValid()) {
        const checkedLessOrGreater = lessOrGreater(problemDate, format[0], maxDate, minDate);
        if (!checkedLessOrGreater.result) {
          const { message, result } = checkedLessOrGreater;
          return buildResponse(message, result);
        }

        return buildResponse(CALENDAR_ERROR_MESSAGES.INCOMPLETE, false);
      }
      else {
        return buildResponse(CALENDAR_ERROR_MESSAGES.INVALID, false);
      }
    }
    else {
      return buildResponse(CALENDAR_ERROR_MESSAGES.INVALID, false);
    }
  }
  else if (isValidDate && value.indexOf('_') === -1) {
    const checkedLessOrGreater = lessOrGreater(date, format[0], maxDate, minDate);
    if (!checkedLessOrGreater.result) {
      const { message, result } = checkedLessOrGreater;
      return buildResponse(message, result);
    }
  }

  return buildResponse('', true);
}
Checks the entered date for validity.
@param {string} value - The value to check.
@param {[string]} format - A moment formats.
@param {Date} minDate - The minimum date.
@param {Date} maxDate - The maximum date.
@returns {{message: string, result: boolean}} - The response object.