Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I replace non-numeric characters in string while excluding periods?

So I have this-

lr_min = $('#lr_min').val().replace(/\D/g,'');

It gets rid of all the nonnumeric characters in the string. How do I exclude periods (.) from this replace?

like image 401
muzzledBYbrass Avatar asked Feb 17 '23 19:02

muzzledBYbrass


1 Answers

You can use

lr_min = $('#lr_min').val().replace(/[^\d.]+/g,'');

The + isn't strictly necessary but will usually give better performances (less replacements)

like image 102
Denys Séguret Avatar answered Feb 19 '23 10:02

Denys Séguret