Validate if one of the fields has been filled out

4

I'm using the Jquery Validation plugin

I need to know if at least one of the fields has been filled out

Fields > Phone, Mobile

I tried to do this:

 $("#Telefone").rules("add", {
                required: $('#Celular').val() == '',
                messages: {
                    required: "Esse campo é obrigatório."
                }
            });

But I did not succeed.

    
asked by anonymous 16.12.2014 / 17:12

1 answer

2

Hello, just do it this way

$("#form").validate({
 rules: {
    Telefone: { require_from_group: [1, ".camposFiltro"] },
    Celular: { require_from_group: [1, ".camposFiltro"] },
});

And in HTML

<input type="text" id="Telefone" name="Telefone" class="required camposFiltro" />
<input type="text" id="Celular" name="Celular" class="required camposFiltro" />
    
16.12.2014 / 18:06