Search code examples
javascriptjqueryinternet-explorermozilla

function that limits fields does not work in mozilla and I.E


I have a function to limit numeric type fields in my web feed. The function is this ;

$(function() {
          $('#idValorTotalProdutoP, #idValorUnitarioProduto, #idProdutoQuantidade, #idValorIcmsNota,#idValorFreteNota, #idValorSeguroNota, #idValorTotalP, #idFunruralNota, #idValorTotalNotaProdutor, #idAlicotaIcmProduto, #idBaseCalculoProduto').on('change keyup input', function() {
            match = (/(\d{0,15})[^.]*((?:\.\d{0,4})?)/g).exec(this.value.replace(/[^\d.]/g, ''));
            this.value = match[1] + match[2];
          });
        });

e no meu html está assim:

<div class=" form-group col-md-3">
    <label class="lb">Valor icms</label> <input type="number"  min="0" id="idValorIcmsNota"  value="{{0}}" class="form-control" ng-model="nota.valorIcms" />                       
</div>

everything works fine in Crome browser but in i.e. and in Mozilla firefox it is not possible to put the comma, it limits the field only up to 15 places and does not let put the comma .. does anyone have any idea how to solve this?


Solution

  • The problem is just a wrong fielg type. You setted it to number. If you need to be able to enter a dot, you need to set the field type to text. Then the script will work just fine on IE and Firefox.