0

I have an element like

<input type="text" id="no_of_days" name="admin_setting[no_of_days]" class="txtbox" maxlength="50" />

when I validate like,

jQuery("form").validate({

     rules :{   
        admin_setting[no_of_days] : "required"
      },
      messages :{

        admin_setting[no_of_days] : "Please enter the No of Days"

      }

   });

It throws the error. Please provide me the way to add the rules inside the validate() function for the element which has the name in array form like "admin_setting[no_of_days]".

I don't want to use .rules() function, as more number of fields to be added in validate() function, instead of calling rules() function for every element.

1 Answer 1

1

You need to quote the key, as it's a non-standard key name (i.e. it contains [...]):

jQuery("form").validate({

     rules :{   
        'admin_setting[no_of_days]' : "required"
      },
      messages :{

        'admin_setting[no_of_days]' : "Please enter the No of Days"

      }

   });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.