I want a Javascript regex to replace only numbers i.e. all others alphabets and special characters are allowed.
Asked
Active
Viewed 259 times
-4
-
A simple search can help you to achieve that. – Mamun Jul 06 '18 at 04:59
-
@Mamun I searched for it and found one but it doesn't entirely accept special characters. – Axel Jul 06 '18 at 05:00
-
Then you should include that in the question mentioning in which part you are struggling... – Mamun Jul 06 '18 at 05:02
-
Actually, that regex was for other languages so couldn't figure out. – Axel Jul 06 '18 at 05:03
1 Answers
0
This should do:
let string= "26kgsl5"
let newString = string.replace(/[0-9]/g, "");
console.log(newString);

Suhas
- 550
- 4
- 11