diegohaz / schm

Composable schemas for JavaScript and Node.js

Home Page:https://git.io/schm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Validating startDate vs endDate

verscph opened this issue · comments

I needed to validate whether the startDate is before the endDate and whether both dates have the right format:

var dateSchema = new schema({
dateRange: {
    type: {
      startDate: {
        type: Date,
        required: true,
        validate: [dateFormatValidator, '{VALUE} is not a valid date!']
      },
      endDate: {
        type: Date,
        required: true,
        validate: [dateFormatValidator, '{VALUE} is not a valid date!']
      }
    },
    required: true,
    validate: [dateRangeValidator, 'startDate must be before endDate!']
  }
});

The validation of dateRange is executed, but the validation of the startDate and endDate format isn't. Is this a bug?