0

With this I can write only numbers:

validaHoraNumero: function(iContTabla,iContFila){

    var self = this;

    $("#hora_"+iContTabla+"_"+iContFila+"_id").keydown(function (e) { 
        if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 || $(this).val().indexOf('.') != -1 || (e.keyCode == 65 && ( e.ctrlKey === true || e.metaKey === true ) ) || (e.keyCode >= 35 && e.keyCode <= 40)) {
            return;
        }
        if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
            e.preventDefault();
        }
    });
},

I need to modify this method to not allow write a decimal point "."

How can I do this? thanks.

Jeanbf
  • 317
  • 1
  • 5
  • 15

1 Answers1

0

Just remove the 190, which is '.'

$("#field").keydown(function (e) { 
    if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110]) !== -1 ||     $(this).val().indexOf('.') != -1 || (e.keyCode == 65 && ( e.ctrlKey === true || e.metaKey === true ) ) || (e.keyCode >= 35 && e.keyCode <= 40)) {
        return;
    }
    if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
        e.preventDefault();
    }
});

https://jsfiddle.net/s3xqtdax/

You can also check this solution:

How to allow only numeric (0-9) in HTML inputbox using jQuery?

Community
  • 1
  • 1
Manjar
  • 3,159
  • 32
  • 44
  • Sorry but now I check and this allow this = " ´ " , what I need add to fix this? his name is "Single quotes" if I remember .thanks – Jeanbf Jun 19 '15 at 21:03
  • Just add 222 which is single quote, I checked here: http://www.theasciicode.com.ar/ascii-printable-characters/single-quote-apostrophe-ascii-code-39.html looks working https://jsfiddle.net/s3xqtdax/1/ – Manjar Jun 19 '15 at 21:09