Page 1 of 1

JS regex to replace any non numeric char or decimal

Posted: Wed Oct 25, 2006 4:02 pm
by Burrito

Code: Select all

<script>
function removeIt(obj)
{
	obj.value = obj.value.replace(/(\D|^\.)/,'');
}
</script>
that gets any non-numeric char (including a decimal point). I need to keep the decimal point.

so:
$53 would change to 53
and:
$53.00 would change to 53.00

etc.

Posted: Wed Oct 25, 2006 4:07 pm
by feyd

Code: Select all

/[^\d\.]/
or

Code: Select all

/[^0-9\.]/

Posted: Wed Oct 25, 2006 4:14 pm
by Burrito
w00t.

thanks