I have a form with multiple date fields each with unique name and id field. I want to validate the date as dd/mm/yyyy. I am using a php codeigniter
based cms fuelcms which auto generates date fields with validator's data attributes. I have set the rule to validate for dateITA format (dd/mm/yyyy), but when I put a date it seems to check for two formats:
I don't know what's causing the issue, since I have disabled my rule so now it is validating against mm/dd/yyyy and I don't know where it is setting that rule because the default is dateISO (yyyy-mm-dd).
How can I achieve the desired effect?
<input type="text" name="date_of_birth" value=""
class="datepicker field_type_date date hasDatepicker" size="12"
placeholder="dd/mm/yyyy" required="" data-date_format="dd/mm/yy"
data-first_day="0" data-show_on="focus" id="date_of_birth" autocomplete="bday"
aria-required="true">
$('#job-form').validate({
errorClass:'small text-danger',
rules: {
date_of_birth: {
dateITA: true
}
}
});
#job-form
is the id of form
Your code:
12/12/2018
is valid but both 31/12/2018
and 12/31/2018
are not valid. This is because your inline class
attribute contains date
, which automatically triggers the date
method of jQuery Validate. Since you're also declaring dateITA
, the plugin is applying two different date rules simultaneously to your field... date
and dateITA
which are in conflict with each other.
Remove the date
class, and the dateITA
rule is working fine:
DEMO: jsfiddle.net/r1kwjv35/