I have an input field, and with JavaScript and React, I'm restricting that field to only numbers:
HTML:
<input type="number" name="worth" id="worth-Valueofproperty-undefined-39916" style="padding: 0px; position: relative; width: 100%; border: none; outline: none; background-color: rgba(0, 0, 0, 0); color: rgba(0, 0, 0, 0.87); cursor: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; opacity: 1; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); height: 100%;">
JS:
validateValue(e) {
return (
e.target.value = e.target.value.replace(/[^0-9,.]/, '')
);
}
This works great, but now I would like to add commas into the input to group hundreds, thousands, etc.
For example:
1000 -> 1,000
100000 -> 100,000
100000000 -> 100,000,000
How can I do this?