Take the 2-minute tour ×

I have the folliwng code working, however I feel that there is a cleaner way of writing it.

<script type="text/javascript">     
    $(document).ready(function () {        
            highlight: function (element, errorClass) {
            unhighlight: function (element, errorClass) {

        $.validator.messages.required = '  *';

the validation message seems like it belongs within the validate function. Is there a way of writing this cleaner?

share|improve this question
Besides $.validator.messages, there are a bunch of other methods that do not go inside the function itself. It's just how it works. –  Sparky Apr 23 '12 at 19:24
add comment

1 Answer

up vote 1 down vote accepted

There isn't a wonderful way to do that without a bunch of statements inside your validate object:

You can specify the messages option in validate, and then for each required element, add a required: '*', like this:

   //your options
   messages: {
      formElementName1: {
         required: '*'
      //repeat for each form element

If you have a lot of elements, this is pretty tedious and I would prefer your method.

share|improve this answer
Wow - yeah. maybe I will leave it as is. –  David K Egghead Apr 23 '12 at 18:17
add comment

Your Answer


