As already stated, the original code was targeting a class, .form1, while the actual form contained id="form1". Fixing the selector to target the id will quickly solve this.
$('#form1`).validate({...
Despite an answer already being posted, I feel the need to also post some important notes regarding some common misconceptions about this plugin.
The .validate() method is only used for plugin initialization, not a method for testing the validity. So putting .validate() inside a click handler makes no sense. .validate() only needs to be called one time, so being called repeatedly upon every click is redundant and unnecessary.
As long as the submit button is inside the <form> tags, there is no need for a click handler as this is automatically captured by the plugin. See: http://jsfiddle.net/B5mVh/6/
If the button is outside of the <form>, you can use the .valid() method to test the form's validity.
$(document).ready(function () {
$('#form1').validate({ // <-- INITIALIZE plugin on your form
// your rules & options
});
// For button OUTSIDE of form tags
$("#name_id").click(function() {
if ($('#form1').valid()) {
alert("form is valid");
} else {
alert("form is invalid");
}
});
});
DEMO: http://jsfiddle.net/B5mVh/4/
However, in your original code, the button is inside the form, so as explained before, there's no need for a click handler at all. But if you want to run some code upon the click event, use the submitHandler (when valid) and invalidHandler (when invalid) callback functions.
$(document).ready(function () {
$('#form1').validate({ // <-- INITIALIZE plugin on your form
// your rules & options,
submitHandler: function(form) {
alert("form is valid");
return false;
},
invalidHandler: function() {
alert("form is invalid");
}
});
});
DEMO: http://jsfiddle.net/B5mVh/5/
Of course, you don't have to use these optional callback functions. The plugin works perfectly fine without them as shown before:
DEMO: http://jsfiddle.net/B5mVh/6/
$("#name_id").click(function() {