DEV Community

loading...
Cover image for how to give number format to a input box text while I am typing it

how to give number format to a input box text while I am typing it

Carlos Alberto
programming the world
・1 min read


<br>
function format_num(id) {<br>
var number = document.getElementById(&quot;principal&quot;).value;<br><br>
var checkedNew = number.split(&#39;.&#39;).join(&quot;&quot;);<br><br>
document.getElementById(&quot;principal&quot;).value = checkedNew.toString().replace(/\B(?=(\d{3})+(?!\d))/g, &quot;.&quot;);<br><br>
}<br>














Discussion (0)