Luey
asked on
jquery validation not equal
how can I validate two fields must not equal each other with jquery?
I know this code works to validate that they are equal. I want to do the opposite.
I know this code works to validate that they are equal. I want to do the opposite.
$("#account_info").validate( {
rules: {
profile_2: { equalTo: "#profile_1"}
},
});
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Conveniently, change "equalTo" to "notEqualTo"
It is already implemented?
ASKER
Tried notEqualTo and it did not work.
Also tried to add the method and cannot get that to work either. I have added other methods and they work but cannot see what is wrong with this one.
here is all the code that I am using.
Also tried to add the method and cannot get that to work either. I have added other methods and they work but cannot see what is wrong with this one.
here is all the code that I am using.
//validation addMethods for my account here
//custom validation rule - text only
$.validator.addMethod("textOnly", function(value, element) {
return !/[0-9]*/.test(value);
}, "Alpha Characters Only.");
$.validator.addMethod("notEqualTo", function(value, element, param) {
return this.optional(element) || value != param;
}, "Please specify a different (non-default) value");
/*--------------------------------------------------------------------------------------*/
$("#account_info").validate( {
errorPlacement: function (error, element) {
$('#'+element.attr("id")+'_label').append(error);
},
rules: {
profile_2: { notEqualTo: "#profile_1"}
},
messages: {
county_ansi: "Setting your location is required. Please enter a city or zip code to search.",
},
submitHandler: function(form) {
$("#loading_box").show();
$("#button_box").hide();
form.submit();
}
});
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This worked as intended