2

I have 13 forms and every form with 5 to six inputs.
Below code is working perfectly but have to repeat for all inputs.

$('#formID').validate({
    rules:{
        inputName:{
            required:true,
            normalizer: function (value) {
                //Trim the value of element for whitespaces
                return $.trim(value);
             }
        }
    },
    messages:{
        inputName: {
            required: "Please fill some description"
        }
    }
});

To trim and validate for each input i tried this so far

$('form input, form textarea').each(function (index, element) {
        var testInput =$(element).attr("name");
        // console.log(testInput+'ehllo');
        $('form').validate({
            rules:{
                testInput:{
                    normalizer: function (value) {
                        //Trim the value of element for whitespaces
                        return $.trim(value);
                    }
                }
            }
        });

    });

But this isn't working

2

1 Answer 1

2

Please check this format.

Validating multiple forms on the same page

example http://jsfiddle.net/K6Tkn/

$('form').each(function() {
    $(this).validate({
        rules:{
            inputName:{
                required:true,
                normalizer: function (value) {
                    //Trim the value of element for whitespaces
                    return $.trim(value);
                 }
            }
        },
        messages:{
            inputName: {
                required: "Please fill some description"
            }
        }
    });
    });
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.