HTML <input type="date" not validating min attribute correctly

534 Views Asked by At

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.

0

There are 0 best solutions below