Top Left Text cha

Website Development Services

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


Security code
Refresh

  • No comments found

Leave your comments

Post comment as a guest

0
Your comments are subjected to administrator's moderation.
X