Skip to content

Instantly share code, notes, and snippets.

@rogerz
Created June 17, 2012 09:22
Show Gist options
  • Save rogerz/2943992 to your computer and use it in GitHub Desktop.
Save rogerz/2943992 to your computer and use it in GitHub Desktop.
jquery validator example
$(function() {
$.validator.addMethod("list", function(value, element, param) {
var isValid = false;
var list = $.parseJSON(param);
$.each(list, function() {
if (value == this) {
isValid = true;
return false;
};
})
return isValid;
});
$("#commentForm").validate({
debug: true,
submitHandler: function(form) {
alert("submit me");
}
});
$("#list").rules("add", {
list: '[1, 2, 3]'
});
});​
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment