-
I need to pass a minimum date and a maximum date so that the input does not accept a certain date, but when I enter the minimum and maximum date it does not detect validation https://codesandbox.io/s/react-hook-form-js-forked-gbsf9?file=/src/App.tsx |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You're using the wrong validation attributes. What you can do is to utilize the RHF rules={{
validate: {
minDate: (date) =>
isAfter(new Date(date), new Date("1993/11/11")) ||
"Please, enter a date after 1993/11/11",
maxDate: (date) =>
isBefore(new Date(date), new Date("2022/25/07")) ||
"Please, enter a date before 2022/25/07"
}
}} |
Beta Was this translation helpful? Give feedback.
You're using the wrong validation attributes.
maxLength
andminLength
are thetype="text"
input attributes. HTML5 forms API doesn't have anytype="date"
validation API.What you can do is to utilize the RHF
validate
callback and provide multiple validation functions in a form of object for ease of use. Something like this: