Ryadel
https://www.ryadel.com/en/html-input-type-number-with-localized-decimal-values-jquery/#comments
HTML
<html>
<head>
</head>
<body>
Script for the sample code posted on <a href="https://www.ryadel.com/en/html-input-type-number-with-localized-decimal-values-jquery/#comments" target="_blank">this post on Ryadel.com tech blog</a>.
<p>
The following textbox will only accept the following keys: backspace delete tab escape enter comma dot Ctrl/cmd+A Ctrl/cmd+C Ctrl/cmd+X home end left right
</p>
<p>
<input type="text" class="number" />
</p>
</body>
</html>
JavaScript
$(function() {
// client-side validation of numeric inputs, optionally replacing separator sign(s).
$("input.number").on("keydown", function(e) {
// allow function keys and decimal separators
console.log(e.keyCode);
if (
// backspace, delete, tab, escape, enter, comma and .
$.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 188, 190]) !== -1 ||
// Ctrl/cmd+A, Ctrl/cmd+C, Ctrl/cmd+X
($.inArray(e.keyCode, [65, 67, 88]) !== -1 && (e.ctrlKey === true || e.metaKey === true)) ||
// home, end, left, right
(e.keyCode >= 35 && e.keyCode <= 39)) {
/*
// optional: replace commas with dots in real-time (for en-US locals)
if (e.keyCode === 188) {
e.preventDefault();
$(this).val($(this).val() + ".");
}
// optional: replace decimal points (num pad) and dots with commas in real-time (for EU locals)
if (e.keyCode === 110 || e.keyCode === 190) {
e.preventDefault();
$(this).val($(this).val() + ",");
}
*/
return;
}
// block any non-number
if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
e.preventDefault();
}
});
});