Joi 验证时间字段

Joi validating time field

存在 属性 时间 (22:30:00) 的对象。

const schema = Joi.object.keys({
  ...
  transactionDate: Joi.date().required(),
  transactionTime: Joi.time().required(), // ???
  ...
});

如何使用 Joi 验证时间字段?

试试这个方法

const schema = Joi.object().keys({
   ...
   transactionDate: Joi.string().regex(/^([0-9]{2})\:([0-9]{2})$/)
})

听说我使用了简单的正则表达式格式。

你也可以使用这个:^([01]\d|2[0-3]):?([0-5]\d)$

上午和下午 \b((1[0-2]|0?[1-9]):([0-5][0-9])([AaPp][Mm]))