-
Details
-
Written by Timothy Johns
-
Category: jQuery
-
-
-
Hits: 7588
This is an example of how to check for duplicates across form fields using jQuery
jQuery.validator.addMethod("unique", function(value, element, params) {
var prefix = params;
var selector = jQuery.validator.format("[name!='{0}'][name^='{1}'][unique='{1}']", element.name, prefix);
var matches = new Array();
$(selector).each(function(index, item) {
if (value == $(item).val()) {
matches.push(item);
}
});
return matches.length == 0;
}, "Value is not unique.");
jQuery.validator.classRuleSettings.unique = {
unique: true
};
$("#myform").validate();
$("#validate").click(function() {
$("#myform").valid();
});
Add comment
Comments