How can I remove strings in an input value except number and point using with regex in JS?

Viewed 23

I have an input that can gets float numbers for example 1.56 I want to replace all strings and other characters except number and . I used this code. It removes all strings and special chars. But this time I can not use . for float number.

 const convertedValue = input.replace(/\D+/g, '');

Can anybody help me to find a way? Thanks

1 Answers

You can use the parseFloat method:

parseFloat("1.56") // returns 1.56
Related