-4

I want a Javascript regex to replace only numbers i.e. all others alphabets and special characters are allowed.

4
  • A simple search can help you to achieve that. Commented Jul 6, 2018 at 4:59
  • @Mamun I searched for it and found one but it doesn't entirely accept special characters. Commented Jul 6, 2018 at 5:00
  • Then you should include that in the question mentioning in which part you are struggling... Commented Jul 6, 2018 at 5:02
  • Actually, that regex was for other languages so couldn't figure out. Commented Jul 6, 2018 at 5:03

1 Answer 1

0

This should do:

let string= "26kgsl5"
let newString = string.replace(/[0-9]/g, "");
console.log(newString);

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.