Closed david-unergie closed 4 years ago
format()
only applies to strings. I would argue the old behavior was incorrect.
In this case @hueniverse, how to implement a "joi.date()" in order to allow string only?
Use Joi.string()
with a regex pattern. There is no option to not allow numbers as input.
But in this case, there is no validation about the date consistency. For example, "2019-13-48" will be accepted…
Like I said, this is not a supported use case. In v16 you can write a custom function validator that checks helpers.original
to be a string.
Ok. I just wanted to point out that the old behaviour may not be so bad. Thanks.
I concur with @david-unergie. Maybe add a new field which forces input to only be a string? Old behaviour is far more logical as it abides by the set format(...)
check
Context
What are you trying to achieve or the steps to reproduce ?
joi.date()
accepts a valid date string or a number of milliseconds. Using.format()
should accept a valid date string, and should reject number in this case.Working with joi v9.2.0:
Failing with v10.6.0 / v11.4.0 / v12.0.0 / v13.7.0 / v14.3.0:
Which result you had ?
A number
What did you expect ?
An error: "value" must be a string with one of the following formats [YYYY-MM-DD]