Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

308
Visualizações
Toggle Div from input text !notmatch, and when match don't display unless

I have a table where you can add rows with inputs for email. When you input email I want toggle to display a hidden DIV when there is No match with a regex !email I've set.

It works, the problem is, if next input has the opposite of the match, div hides back in.

So if I add rows and input emails with @gmail I want the div to remain hidden. But if in all the rows there's any other row input with at least one email not from !@gmail I want to show hidden div and not hide it even if the next input is an input with @gmail, unless you delete all rows with !match then don't show div.

var i = 1;

$("#addbutton").click(function() {
  $("#usertable").append('<tr>' +
    '<td><input id="myinputs" class="form-control input-lg email1" type="email" name="mail[]" required /></td>' +
    '<td><button type="button" class="removebutton" title="Remove this row">X</button></td></tr>').find("input").each(function() {});
  i++;
});;

$(document).on('click', 'button.removebutton', function() {
  $(this).closest('tr').remove();
  return false;
});

$(document).on("keyup change", "#myinputs", function() {
  $(".mydiv").toggle(!/@gmail./ig.test(this.value) && !/^\s*$/.test(this.value))
});
.mydiv {
  display: none;
}
<form action="" method="post" enctype="multipart/form-data">
  <div class="form-floating mb-3 mt-3">
    <input class="btn btn-primary" type="button" id="addbutton" value="Add Row" title="Add more input rows">
    <br>

    <table class="thetable" id="usertable">
      <tr>
        <td><b>Mail: </b></td>
      </tr>

      <tr>
        <td><input id="myinputs" class="form-control input-lg email" type="email" name="mail[]" required /></td>
      </tr>
    </table>
  </div>

  <div class="form-floating mb-3 mt-5 mydiv">
    Show only if theres one email not from gmail
  </div>

  <div class="form-floating mb-3 mt-5">
    <input class="btn btn-primary" type="submit" name="submit" value="Submit" />
  </div>
</form>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

about 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda