user3653474
user3653474

Reputation: 3854

validate date after current datetime v-validate in vue.js

I want to validate datetime field

<datetime v-validate="'before:2016-05-25|date_format:yyyy-MM-dd|required'" format="YYYY-MM-DD" name="DateTime" width="100px" id="DateTime" :class="['form-control', {'is-invalid': errors.has('DateTime')}]" v-model="DateTime" ></datetime>

This part is working and validating also.

This is only accepting and validation date but i want to enter time also, when i enter yyyy-MM-dd H:i:s it does not validate date time anymore and i want to make this date before:2016-05-25 dynamic it should get the current date time.

Any help is highly appreciated.

Upvotes: 0

Views: 1691

Answers (1)

tony19
tony19

Reputation: 138536

Part of the problem is your date_format pattern string for the time (H:i:s):

  • H is the pattern for hour (not zero-padded)
  • i is the pattern for ISO day of the week
  • s is the pattern for seconds (not zero-padded)

But time is usually shown as HH:mm:ss:

  • HH is the pattern for hour (zero-padded)
  • mm is the pattern for minutes (zero-padded)
  • ss is the pattern for seconds (zero-padded)

Also, the before param must match the date_format pattern string, so if a time pattern were included, the before param would also need to include a time value.

For example, to validate a date before 2016-MAY-25 at 12:30pm:

<datetime v-validate="'before:2016-05-25 12:30:00|date_format:yyyy-MM-dd HH:mm:ss|required'">

demo

Upvotes: 1

Related Questions