3

How can I refer to the second input in this jsfiddle while defining validation rules? I am thinking at something like "postArray.inputOne" instead of inputOne, as I do for the first one. Of course, it doesn't work. Is there any way I can do it?

My HTML looks like this:

<form id="formId" method="post" action="">
    <input type="text" name="inputOne" />
    <input type="text" name="postArray[inputOne]" />
</form>​

The validation rules look like this:

$("#formId").validate({
    rules: {
      inputOne: {
        required: true
      }
    },
    messages: {
      inputOne: {
        required: "Required!"
      }
    }
});    

Thanks!

1 Answer 1

2

You can validate any text field by name

    $(document).ready(function () {

    $("#formId").validate({
        rules:{
            "inputOne":{
                required:true
            },

            "postArray[inputOne]":{
                required:true
            },

            messages:{
                "inputOne":"This field is required",
                "postArray[inputOne]":"This field is required"
            }
        }
    });
});

Hope it will help.....

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.