Input field value - remove leading zeros

raja picture raja · Feb 27, 2009 · Viewed 57.1k times · Source

I have a textbox in Javascript. When I enter '0000.00' in the textbox, I want to know how to convert that to only having one leading zero, such as '0.00'.

Answer

Umar picture Umar · Aug 12, 2009

More simplified solution is as below. Check this out!

var resultString = document.getElementById("theTextBoxInQuestion")
                           .value
                           .replace(/^[0]+/g,"");