1

I want to use "jQuery validation plugin" (http://jqueryvalidation.org/) with arrays.

I tried this solution:

Validating array inputs using jquery validation plugin

But it's not working for me: only one element per array is being check.

My HTML is:

<form id="signupForm" method="get" action="">
    <fieldset>          
        <p>
            <label for="username">Username</label>
            <input name="username[]" type="text">
        </p>
        <p>
            <label for="username">Username</label>
            <input name="username[]" type="text">
        </p>
        <p>
            <input class="submit" type="submit" value="Submit">
        </p>
    </fieldset>
</form>

And my jQuery is:

$("#signupForm").validate({
    rules: {
        'username[]': "required"
    },
    messages: {
        'username[]': {
            required: "Please enter a username"
        }
    }
});

Here a jsFiddle: https://jsfiddle.net/t14ft1ny/

2

0

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.