-1

Backspace/Delete not working in Mozilla Firefox for Jquery alphanumeric validation .

<input type="text" id="myTextBox" />
$("#myTextBox").bind("keypress", function(event) { 
    var charCode = event.which;

    var keyChar = String.fromCharCode(charCode); 
    return /[a-zA-Z0-9]/.test(keyChar); 
});

click here for demo

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
Sush
  • 87
  • 1
  • 9

1 Answers1

2

Use this code

<input type="text" id="myTextBox" />
$("#myTextBox").bind("keypress", function(event) { 
        var charCode = event.which;

        if(charCode == 8 || charCode == 0)
        {
             return;
        }
        else
        {
            var keyChar = String.fromCharCode(charCode); 
            return /[a-zA-Z0-9]/.test(keyChar); 
        }
    });
Gaurav Agrawal
  • 4,244
  • 9
  • 39
  • 59
  • Can I use this code for delete key ? Is this the correct way of using? `if(charCode == 'undefined'){return; }` – Sush Mar 12 '13 at 11:36