-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,753
  • 72
  • 57
  • 129
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,355
  • 10
  • 42
  • 61
  • 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