I'm trying to integrate some custom validation into my form for specific fields.
I have two, but I'm focusing on yy/mm/dd
for this I was able to find this expression:
^\d{2}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$
Which I added into this piece of jquery, which I am reusing from a Canadian postal code custom validation which works
//date format yy/mm/dd
jQuery.validator.addMethod("yearMonthDay", function (yymmdd, element) {
return this.optional(element) ||
yymmdd.match(/^\d{2}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$/);
}, "Please use the correct format yy/mm/dd.");
This works in the way that I can see the error by the field when someone types in it, but I'm able to submit anything, so this isn't working.
$("#form").validate({
rules: {
Birthdate: {
required: true,
yearMonthDay: true
}
}
});
Can anyone be of assistance to me? Show me where I've gone wrong?