Keyboard input type number

2

I am creating an app with angularjs and Ionic. I have some inputs type number but in the android device, the keyboard that presents me is with the option to add a period (.) And it is not what I need.

I tried:

if (
        ($.inArray(e.keyCode, [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 8, 13, 190, 189]) == -1) // digits, digits in num pad, 'back', 'enter', '.', '-'
        || (e.keyCode == 190 && $(e.target).val().indexOf(".") != -1) // not allow double dot '.'
        || (e.keyCode == 190 && $(e.target).val().length == 0) // not allow dot '.' at the begining
    ) {
        e.preventDefault();
    }

Also

text = text.replace('.', '');

Also

<input type="number" pattern="[0-9]*" ng-model="nuevo_cliente.numero_nueva_direccion" placeholder="Número">

All this within the event keyup without any results. I can not delete the value point.

$(':input[type="number"]').on('keyup', function(e) {
    var model = $(this).attr('ng-model');
    var myRegex = /^[0-9]\d*$/;
    var text = $(this).val();
    if (
        ($.inArray(e.keyCode, [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 8, 13, 190, 189]) == -1) // digits, digits in num pad, 'back', 'enter', '.', '-'
        || (e.keyCode == 190 && $(e.target).val().indexOf(".") != -1) // not allow double dot '.'
        || (e.keyCode == 190 && $(e.target).val().length == 0) // not allow dot '.' at the begining
    ) {
        e.preventDefault();
    }
    if (myRegex.test(text)) {
        console.log("fdsf");
        text = removeDiacritics(text);
        text = text.replace('_', '');
        text = text.replace('-', '');
        text = text.replace('.', '');
        text = text.replace(/[^\w\s]/gi, '');


    }
    $scope.$apply();

});
    
asked by sioesi 24.03.2017 в 18:06
source

1 answer

1

Try to do it like this:

  • Subscribe to the input event, which triggers each time the value of input is modified.

  • Make replace of the current value of input and remove the characters you want.

Example: Take all points ( . ) using a RegExp .

$(document).on('input', 'input[type="number"]', function() {
  this.value = this.value.replace(/\./g,'');
});
    
answered by 24.03.2017 / 19:17
source