I am using yup to validate the values in the input field:
const dateToCheck = yup
.date()
.nullable()
.transform((curr, orig) => (orig === '' ? null : curr))
.required()
.min(minDate, 'Date cannot be this early')
.max(maxDate, 'Date too much in the future')
.test('format', 'Date is invalid', date => (date?.getFullYear() ?? 0) <= 9999)
I have been trying to figure out how to check if the input date has the correct format? Because of how yup works, both 01.01.2000
and 2000/01/01
will pass date
validation but I would like to be able to only dd.MM.yyyy
format to pass or only yyyy/MM/dd
format to pass not both and then every other format which would be valid otherwise be labelled as invalid instead. What is the correct way to do it in yup?
from How to check if the date has valid format in Yup?
No comments:
Post a Comment