0

I am using jQuery Validation Plugin (http://bassistance.de/jquery-plugins/jquery-plugin-validation/)

I have wrote following rule

jQuery.validator.addMethod("valueNotEquals", function(value, element, arg){
return arg != value; }, "Value must not equal arg.");

I have wrote following rules and message

    rules: {
        filelist:{required:function() {return jQuery('input[name|="producthosting"]:checked').val() == 'us';},valueNotEquals:"-1"}
    },
    messages: {
        filelist:{
            required:"Please select a file",
            valueNotEquals:"Please select a valid file"
        }
    }

Now, I need to validate valueNotEquals only if input with name "producthosting" is "us"

right now, above rule throws error even if "producthosting" value is not equal to "us"

How can I achieve it?

I-M-JM
  • 15,732
  • 26
  • 77
  • 103

1 Answers1

0

try this way:

first add the method

jQuery.validator.addMethod("valueNotEquals", function(value, element, param) {
  return this.optional(element) || value != param;
}, "Please specify a different (non-default) value");

Then use it like this:

$("form").validate({
  rules: {
    filelist: { valueNotEquals: "us" }
  },
  messages: {
        filelist:{
            required:"Please select a file",
            valueNotEquals:"Please select a valid file"
        }
});

ALL D BEST

xkeshav
  • 53,360
  • 44
  • 177
  • 245
  • Similar Question : http://stackoverflow.com/questions/3571347/how-to-add-a-not-equal-to-rule-in-jquery-validation – xkeshav May 25 '11 at 06:10