coffeemonitor coffeemonitor - 1 year ago 154
Javascript Question

Javascript Regular Expressions - Replace non-numeric characters

This works:

var.replace(/[^0-9]+/g, '');

That simple snippet will replace anything that is not a number with nothing.

But decimals are real too. So, I'm trying to figure out how to include a period.

I'm sure it's really simple, but my tests aren't working.

Answer Source

Did you escape the period? var.replace(/[^0-9\.]+/g, '');

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download