Sagar Gautam
Sagar Gautam

Reputation: 9359

Validating date input field in parsley js

For some reason, I don't have datepicker for the date input field and I want to allow to enter value in mm/dd/yyyy format only. I've used parsley js for validation.

Somehow, I've managed to validate email, image, digits field and i don't find built in validation method for date.

Is there any parsley rule for the date ?

Upvotes: 1

Views: 2014

Answers (1)

timbo
timbo

Reputation: 14314

Yes, there is. It's unfortunately not documented but it was added in version 2.7 according to the CHANGELOG

The date parse code is here

It expects YYYY-MM-DD so you could do something like

<input type="text" id="somedate"
       placeholder="YYYY-MM-DD"
       data-parsley-type="date"
       data-parsley-type-message="Date must be YYYY-MM-DD"
       data-parsley-mindate="{{ today|date:'Y-m-d' }}"
       data-parsley-mindate-message="Date must be after today"
       required>

Upvotes: 1

Related Questions