jQuery validate : multiple form, single validation

Posted by I-M-JM on Stack Overflow See other posts from Stack Overflow or by I-M-JM
Published on 2011-01-12T04:44:58Z Indexed on 2011/01/12 4:53 UTC
Read the original article Hit count: 265

Filed under:

Hi all

I have 2 forms, namely (ids mentioned) 'add_product' and 'edit_product'

Now I am using jQuery validation plug-in, both the forms have same validation (similar to mentioned in following example)

jQuery("#add_product").validate({
    rules: {
        name:"required",
        price:"number"
    },
    messages: {
        name:"Please enter Plan Name",
        price:"Enter a valid number"
    }

});

and

jQuery("#edit_product").validate({
    rules: {
        name:"required",
        price:"number"
    },
    messages: {
        name:"Please enter Plan Name",
        price:"Enter a valid number"
    }

});

I want to combine them into 1 rule/function, how can I achieve this?

Thanks

© Stack Overflow or respective owner

Related posts about jQuery