Required field fill

1

How do I enforce that between two fields, at least one of them is mandatory (is it filled out)? For example, the fields Celular and Telefone can not be saved empty, only one of them.

My code:

//..
}
else ((txtNome.Text == "") || (maskedCPF.Text == "") || (maskedCEP.Text == "") || (txtNum.Text == "") || (maskedCelular.Text == "") || (txtTelefone.Text == ""))     
{
  MessageBox.Show("Os Campos com * são de Preenchimentos Obrigatórios!");
}

In this case he is obliging the two fields (Cellular and Phone) to be filled. I want it to be possible to save with the filled cell field and the empty phone field or vice versa.

    
asked by anonymous 30.06.2016 / 23:25

1 answer

2

It would look something like this:

else ((txtNome.Text == "") || (maskedCPF.Text == "") || (maskedCEP.Text == "") ||
    (txtNum.Text == "") || ((maskedCelular.Text == "") && (txtTelefone.Text == "")))

Using the and operator ( && ) only if the two are empty is there a problem.

Or depending on the case:

if ((txtNome.Text != "") && (maskedCPF.Text != "") && (maskedCEP.Text != "") &&
    (txtNum.Text != "") && ((maskedCelular.Text != "") || (txtTelefone.Text != "")))
    
30.06.2016 / 23:32