I am currently using jquery validation plugin to validate my form, here i want to validate Landline number and mobile number .User want to enter any one.So I Want to use Or condition in jquery validation rules.
rules{ 'landline':{ required:true }, 'mobile':{ required:true } }
How to make any one field mandatory.
If you want the error messages to properly toggle and keep your code looking concise, just use the method that was created specifically for this situation.  The rule/method is called require_from_group and included in the additional-methods.js file.
$(document).ready(function () {
    $("#form").validate({
        rules: {
            landline: {
                require_from_group: [1, '.phone'],
                number: true
            },
            mobile: {
                require_from_group: [1, '.phone'],
                number: true
            }
        }
    });
});
DEMO: http://jsfiddle.net/t45dc/
And to optionally combine both error messages into one, use the groups option...
$(document).ready(function () {
    $("#form").validate({
        rules: {
            landline: {
                require_from_group: [1, '.phone'],
                number: true
            },
            mobile: {
                require_from_group: [1, '.phone'],
                number: true
            }
        },
        groups: {
            phones: 'landline mobile'
        }
    });
});
DEMO: http://jsfiddle.net/t45dc/1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With