Custom Dynamic Error Messages with JQuery Unobtrusive Validation

This could be helpful for the circumstances when you need to dynamically determine the error message for one of you custom validators:

$.validator.addMethod('customvalidatorname', function(value, element, parameters) {
	return validationFunction();
}, function(params, element) {
	return errorMessageFunction();

The third parameter to addMethod can be a function which dynamically determines your error message.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.