[javascript] Remove leading zeros from a number in Javascript

Possible Duplicate:
Truncate leading zeros of a string in Javascript

What is the simplest and cross-browser compatible way to remove leading zeros from a number in Javascript ?

e.g. If I have a textbox value as 014 or 065, it should only return 14 or 65

This question is related to javascript html parseint

The answer is


regexp:

"014".replace(/^0+/, '')

It is not clear why you want to do this. If you want to get the correct numerical value, you could use unary + [docs]:

value = +value;

If you just want to format the text, then regex could be better. It depends on the values you are dealing with I'd say. If you only have integers, then

input.value = +input.value;

is fine as well. Of course it also works for float values, but depending on how many digits you have after the point, converting it to a number and back to a string could (at least for displaying) remove some.