Remove all non-numeric characters in JavaScript


In this tutorial, you learn to remove all non-numeric characters in Javascript. The implementation can be done using .replace method. There is several way to implement this. You can check the code below.

const str1 = "abc123de45f6".replace(/\D/g, "");
const str2 = "-12345.50 €".replace(/[^\d.-]/g, '');
const str3 = "abc444de45f6".replace(/[^0-9]/g, '');
console.log(1, str1);
console.log(1, str2);
console.log(1, str3);

The output will be:

Back To Top