# Numeric input with comma
#JavaScript
[Numeric input with comma](https://codepen.io/hibi-myzk/pen/poWGBxp)
```js
(function () {
if (!Element.prototype.matches)
Element.prototype.matches = Element.prototype.msMatchesSelector;
const filter = (e) => {
let v = e.target.value
.replace(/[0-9]/g, function (x) {
return String.fromCharCode(x.charCodeAt(0) - 0xfee0);
})
.replace(/[^0-9]/g, "")
.replace(/^0+/g, "")
.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
e.target.value = v;
};
let isComposing = false; // IE11対応が不要の場合は InputEvent.isComposing が使用できます。
document.addEventListener("input", (e) => {
if (!isComposing && e.target.matches("input.input-numeric")) filter(e);
});
document.addEventListener("compositionstart", (e) => {
if (e.target.matches("input.input-numeric")) {
isComposing = true;
}
});
document.addEventListener("compositionend", function (e) {
if (e.target.matches("input.input-numeric")) {
isComposing = false;
setTimeout(function () {
filter(e);
}, 0);
}
});
})();
```