I am creating an app with angularjs and Ionic. I have some type number inputs but on 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 result. I can't remove the dot from the value.
$(':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();
});
Try doing it like this:
Subscribe to the event
input
, which fires every time the value ofinput
is modified.Make a
replace
of the current value ofinput
and remove the characters you want.Example: Get all points (
.
) using aRegExp
.