$(function(){ new FormValidator('zipcode-form', [{name: 'zipcode',display: 'Zip Code',rules: 'trim|required|alpha_numeric|exact_length[6]'}], function(errors) { if (errors.length > 0) { var form = $('form[name="zipcode-form"]'); form.find('.form-group.error').removeClass('error'); form.find('.form-group .error-text').html(''); // Show the errors $.each(errors, function(index, value) { var obj = $('[name=' + value.name + ']'); obj.closest('.form-group').addClass('error'); obj.siblings('.error-text').html(value.message); }); } }); });