Onkeyup event with Jquery

1

I need to do the following onkeyup of inputs that have class virgula_nao , obey the function:

$(document).on('keyup', '#virgula_nao', function () {
    valor_do_input = valor_do_input.value.replace(/,/gi, ".");}
});

I do not know how to do this. Can anyone help me?

    
asked by anonymous 30.06.2017 / 15:22

2 answers

1

As I understand it, you want to replace the commas with periods in the keyup event, here is an example of how to do with jquery :

$(document).on('keyup', '.virgula_nao', function(e) {
  var keycode = e.which ? e.which : event.keyCode;
  if (keycode == 110 || keycode == 188) {
    e.preventDefault();
    $(this).val($(this).val().replace(",", "."));
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>Input1:<inputclass="virgula_nao" /><br><br>
Input 2: <input class="virgula_nao" />
    
30.06.2017 / 15:32
0

Would not it be better to start using a masking plug-in?

You can define a pattern in the inputs.

Example: $('.money').mask('000.000.000.000.000,00', {reverse: true});

    
30.06.2017 / 15:38