1

I'm trying to restrict a field to input specific values like only floats, i'm using keypress event to handle it. It is working fine on desktop browser but not working on mobile devices. I'm using android

    $(function() {
    $(document.body).on('keypress', '.number-only', function (evt) {
        var charCode = (evt.which) ? evt.which : event.keyCode;
        var value = $(this).val();
        var dotcontains = value.indexOf(".") != -1;
        if (dotcontains){
            if (charCode == 46) return false;
        }
        if (charCode == 46){
            return true;
        }
        if(charCode > 31 && (charCode < 48 || charCode > 57)){
            return false;
        }
        return true;
    });
});
Gautam Surani
  • 1,136
  • 10
  • 21
Asad Iqbal
  • 11
  • 3

0 Answers0