I have a form with a date field. The field is required and should not allow a date sooner than 2 days from the current date.
<input type="date" id="DayDate" name="DayDate"
class="form-control day-date input-validation-error" min="2023-05-09"
placeholder="Date" data-val="true" data-val-required="Date is required." required />
<span class="text-danger field-validation-error" data-valmsg-for="DayDate"
data-valmsg-replace="true"></span>
The calendar appears to format correctly and disables all days preceding 2023-05-09.
Selecting any date that is enabled outputs a validation error of Please enter a value greater than or equal to NaN.
I tried adding the following rule in jQuery:
$("#DayDate").rules("add",
{
required: true,
min: "2023-05-09",
messages: {
required: "Required",
min: "2 Day Minimum"
}
});
});
Even after the above code, the control's rules.min value says NaN.
Can't the min attribute be used for an input type=date control? I'm missing a detail, but I don't see it.
minrule is working as designed. Refer to the documentation.minonly takes a number, hence theNaN(Not a Number) error. jqueryvalidation.org/min-method If you want a rule that evaluates dates then you'll need to write a custom method for that.2023-05-18and all days prior to that date are disabled?type="text"field along with a custom jQuery Validate method.