Completing this task seems straightforward. I need to eliminate any non-numeric characters from an input field specified as type "number" in Firefox when a key is pressed.
The code snippet provided:
$("#field").on("keyup", function() {
regex = /[\\D]+/;
$(this).val( $(this).val().replace(regex, '') );
});
However, the issue arises where entering a non-numeric character causes the entire content of the field to be replaced by an empty string.
For instance:
234d = emptied > should become 234
Solution (discussed here due to question closure):
After investigating further, it appears that the problem lies with the field type. When using an input field of type "number" and introducing non-numeric characters, Firefox displays them but does not store them in the input object. Switching to a text input resolves the issue. It appears to be specific to Firefox.
I believe this question stands out as unique because it pertains to a Firefox-related complication with input fields of type "number".