Showing posts with label RegExp. Show all posts
Showing posts with label RegExp. Show all posts

Monday, 15 August 2011

Trim leading zeros using javascript

Using simple RegExp in javacript can easily trim all leading zeros.


 
var numberString = ‘00220’;
var noLeadingZerosString = numberString.replace(/^0+/, ‘’); // noLeadingZerosString  = ‘220’;