Change form when typed

1

I have a page, where I search by name, cpf or contract, and I'm having difficulty resizing the form when typing.

I think so, when I start typing the characters, you already know that it is by name and it appears the form of size x, if I start typing number, check if it is bigger than 6 numbers is cpf and already inserts the mask when typing and if you start typing numbers and it's less than 11 it's a contract.

I use this data to search a query in SQL Server 2012, depending on the value entered in input .

<span style="color: #ffffff"><strong>Contrato:</strong></span>
<input name="inpcont" type="text" required  id="inpcont" placeholder="Buscar..." onBlur="MM_validateForm('inpcont','','RisNum');return document.MM_returnValue" size="08" maxlength="8"/>
<input id="btnBusca" type="image" src="img/lupasemfundo-22x22.png" vspace="0" hspace="0" onclick="index.php.frmbuscacontrato.submit()"/>
    
asked by anonymous 16.08.2016 / 14:35

1 answer

0

You can use the mask plugin of jquery, apply the mask only when the input value is numeric and remove it if you enter some other character.

$(document).ready(function() {

  $("#nomeCpf").on('keyup', function(e) {

    if ($(this).data('mask') == undefined && $.isNumeric($(this).val())) {
      $(this).mask('000.000.000-00', {
        reverse: false
      });
    } else if($(this).mask) {
      $(this).unmask();
    }
  });

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scripttype="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.0/jquery.mask.js"></script><span><strong>Contrato:</strong></span><inputid="nomeCpf" name="inpcont" type="text" required id="inpcont" placeholder="Buscar..." size="12" />
    
30.10.2018 / 13:59