Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

302
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda