How to strip all non-numeric characters from string in JavaScript

2 Answers

0 votes
s = '2a1-0/R@a9f#4K$$cC3K^htPam8vlQWhJ';

s = s.replace(/\D/g,'');

console.log(s);



/*
run:

2109438

*/

 



answered Jun 14, 2020 by avibootz
edited Jun 15, 2020 by avibootz
0 votes
s = '2a1-0/R@a9f#4K$$cC3K^htPam8vlQWhJ';

s = s.replace(/[^0-9]/g, '');

console.log(s);



/*
run:

2109438

*/

 



answered Jun 14, 2020 by avibootz
edited Jun 15, 2020 by avibootz
...