jquery validator addmethod custom message

Custome message can be added in the validator addMethod, example below, the $.validator.messages.currency_limit carry the different message for different condition.

//value validation
jQuery.validator.addMethod("currency_limit", function(value, element) {
var cond = true;
if( $("#currency").val() == "sgd" ){
	var maxAmt = 500;
	if( value > 500 ){
		$.validator.messages.currency_limit = "Maximum amount is "+maxAmt
		return false;
	}else if( value <= 500 ){ return true; }
}
if( $("#currency").val() == "usd" ){
	var maxAmt = 10000000;
	if( value > 10000000 ){
		$.validator.messages.currency_limit = "Maximum amount is "+maxAmt
		return false;
	}
	else if( value <= 10000000 ){ 
		return true;
	}
}
$.validator.messages.currency_limit
});

By Keenlio, June 3, 2014

What do you think?

Leave a Reply

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


6 − two =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>