Search code examples
validationvue.jsvuejs2vuelidate

Vuelidate date input


I'm using vuelidate in my vue app. I want to set validation for date minDate for one week from now and maxDate for 3 months from now.

<label class="input__label" for="account_date">Ważne do:</label>
<input type="date"
       class="input__col"
       id="account_date"
       v-model="date"
       @input="$v.date.$touch"
       required>

-

date: {
    required,
    //minDate
},

I can't find anything about date in vuelidate docs.


Solution

  • Unfortunately, there are no built-in validators for date in vuelidate: https://monterail.github.io/vuelidate/#sub-builtin-validators

    Anyway, you can use JS lib like luxon and create your custom validator to check dates.

    Luxon has great documentation where you can find really helpful methods like plus or diff that can be handy in your case :)