You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a query parameter of date string and set convert option to false. Joi.validate fails and returns error "'startDate' must be a number of milliseconds or valid date string" even though the string is a valid date string.
The text was updated successfully, but these errors were encountered:
A string is not a date, it needs to be coerced to validate, convert is almost always needed when validating from a JSON. If you need the original string you can add .raw().
@Marsup I ran into this today. My goal is to convert for Joi validation but keep the original value otherwise. Is there any way to do so? E.g.
letschema=Joi.object().keys({// format is basically pointless with convert=falsedateStr: Joi.date().format('YYYY-MM-DD').options({convert: false}),someNumber: Joi.number()})letpayload={dateStr: '2016-04-07',someNumber: '17'}letresult=Joi.attempt(payload,schema)// want: result.dateStr to be a string, result.someNumber to be a number (not string)
I have a query parameter of date string and set convert option to
false
. Joi.validate fails and returns error "'startDate' must be a number of milliseconds or valid date string" even though the string is a valid date string.The text was updated successfully, but these errors were encountered: