Remove/ truncate leading zeros by javascript/jquery

Somnath Muluk picture Somnath Muluk · Nov 26, 2011 · Viewed 133.8k times · Source

Suggest solution for removing or truncating leading zeros from number(any string) by javascript,jquery.

Answer

Guffa picture Guffa · Nov 26, 2011

You can use a regular expression that matches zeroes at the beginning of the string:

s = s.replace(/^0+/, '');