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
?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With