$(function(){ // check if there is an error div set up and use that instead of each field if ($('.errorBox').length){ jQuery.validator.messages.required = null; jQuery.validator.setDefaults({ errorClass: "errorBox", invalidHandler: function(e,v){ if (v.numberOfInvalids()) { var message = 'There is a problem with one or more fields. They have been highlighted.'; $(".errorBox").html(message).show(); } else { $(".errorBox").hide(); } }, errorLabelContainer: $('.errorBox'), wrapper: "li" }); } // custom validations $.validator.addMethod("phoneUS", function(phone_number, element) { phone_number = phone_number.replace(/\s+/g, ""); return this.optional(element) || phone_number.length > 9 && phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/); }, "Please specify a valid phone number"); });