This works:
var.replace(/[^0-9]+/g, \'\');
That simple snippet will replace anything that is not a number with nothing.
But decimals
Did you escape the period? var.replace(/[^0-9\.]+/g, '');
var.replace(/[^0-9\.]+/g, '');