I need to set dynamic validation message for a custom date range validator for input from datepicker.
I have created a validator method like -
$.validator.addMethod("minMaxDatevalidation", function (value, element) {
...})
And created a custom rule like -
$(element).rules("add", {
minMaxDatevalidation: true,
messages: { minMaxDatevalidation: "The " + fieldDisplayName + " field
must be on or after the " + moment(pastDate).format("DD/MM/YYYY") + "."
}
});
But this validation messages in the above add rules section - this I want dynamic - for date selected than a particular year then above or if selected date is more than a particular year than future error message.
I tried to return custom message from validator addMethod, but it's not working.
Any help regarding setting dynamic message in the rules section would be great.
Using Jquery datepicker.
$.validator.addMethodmethods are not jQuery's, these are usually provided by validator plugins. Please check your page's source code to see if there is any other validation library included other than jQuery.addMethod. This method takes a third parameter, which can be a function returning the message string. Check this answer for more details: stackoverflow.com/questions/13352626/…