coffeemonitor coffeemonitor - 4 months ago 18
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.


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