问题
There is object with a property time (22:30:00).
const schema = Joi.object.keys({
...
transactionDate: Joi.date().required(),
transactionTime: Joi.time().required(), // ???
...
});
How to validate a time field using Joi
?
回答1:
Try this way
const schema = Joi.object().keys({
...
transactionDate: Joi.string().regex(/^([0-9]{2})\:([0-9]{2})$/)
})
Hear I have used simple regex format.
You can also use this : ^([01]\d|2[0-3]):?([0-5]\d)$
for AM and PM \b((1[0-2]|0?[1-9]):([0-5][0-9])([AaPp][Mm]))
AM PM
来源:https://stackoverflow.com/questions/53545182/joi-validating-time-field