I have made a validation middleware whose code is given below like this.
export const validateMiddleware = async (req, res, next) => {
const validateExpression = Joi.object()
.keys({
'startDate': Joi.string()
.optional()
.allow(''),
'endDate': Joi.string()
.optional()
.allow('')
});
const {
error
} = validateExpression.validate(req.query, {
'convert': false,
'abortEarly': false
});
if (error) {
// Return response regarding that error.
} else {
next();
}
};
I need to validate that startDate and endDate fields should be string of format YYYY-MM-DD also need to validate that startDate < endDate date value. How can I achieve this using Joi in Node JS ?.