How to block a "Comma" in HTML input with Firefox browser?
This Javascript code works for Opera Browser:
// ----- Block the "COMMA" for all inputs.
$(document).keydown(function(e) {
var keyCode = e.keyCode || e.which;
if(keyCode==188){
// alert("COMMA has been pressed on the keyboard...") ;
e.preventDefault(); // Note, "preventDefault" has to be within "if".
}
});
CodePudding user response:
keyCode
has been deprecated. Use e.key
instead.
document.addEventListener('keydown', e => {
if (e.key === ',') {
e.preventDefault();
return false;
}
})
CodePudding user response:
Found this : https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode
Would that be the reason ?
CodePudding user response:
Here is what worked for Firefox and 2 other browsers:
// ----- Block the "COMMA" for all inputs.
document.addEventListener('keydown', function(e) {
if (e.key === ',') {
e.preventDefault();
return false;
}
})
Thanks