Validate if one of the fields has been completed

Asked

Viewed 703 times

4

I’m using the plugin Jquery Validation

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

Fields> Phone, Mobile Phone

I tried to do so:

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

But I was unsuccessful.

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" />
  • what comes to be ". fieldsFilter" ?

  • a class Voce will add to inputs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.