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.0
It sounds like you just want to remove leading zeros unless there's only one left ("0" for an integer or "0.xxx" for a float, where x can be anything).
This should be good for a first cut:
while (s.charAt(0) == '0') { # Assume we remove all leading zeros
if (s.length == 1) { break }; # But not final one.
if (s.charAt(1) == '.') { break }; # Nor one followed by '.'
s = s.substr(1, s.length-1)
}
Try this:
<input type="text" onblur="this.value=this.value.replace(/^0+(?=\d\.)/, '')">