Delete, Backspace, Tab and Arrow keys are not working in Firefox when applying validation.


To get this work in Firefox.

<input id="Destination" value="" placeholder="Destination">


$('#Destination').on('keypress', function (e) {

    var regex = new RegExp("^[a-zA-Z0-9_ \b]+$");
    var key = String.fromCharCode(!e.charCode ? e.which : e.charCode);   
    
    var keystobepassedout="ArrowLeftArrowRightDeleteBackspaceTab";
    if(keystobepassedout.indexOf(e.key)!=-1)
    {
      return true;
    }
    
    if (!regex.test(key)) {
        e.preventDefault();
        return false;
    }

});

Try it

Leave a Reply

Your email address will not be published. Required fields are marked *