-1

having a few issues here..

In the Fiddle below, I have setup the scenrio where I am currently getting this output:

1,11,111,1111

I need to be able to pad any digits which are less than 4 digits with a "0", so my output would look like so.

0001,0011,0111,1111

Any help is much appreciated.

var text = 'AAA0001 BBB0011 CCC0111 DDD1111';
onlynumbers = text.replace(/[^0-9]/g, ',');
noduplicatecomma = onlynumbers.replace(/,[,0]+/g, ',');
noleadingcomma = noduplicatecomma.replace(/^,/, '');
cleaned = noleadingcomma.replace(/,$/, '');

alert(cleaned);

Fiddle Here

1 Answers1

0

Take out the 0 on noduplicatecomma line

noduplicatecomma = onlynumbers.replace(/,[,]+/g, ',');
Emin
  • 73
  • 7