Click to See Complete Forum and Search --> : Manipulating input


florida
05-20-2003, 11:03 AM
I have an input box done in javascript. When a number is entered it works but if someone enters a comma such as in the input "200,000" it throws my computation off. I need to compute the number 200000.

Please advise how I can get rid of the comma when entered in. Should I be leaning toward a reg expressionsubstitution? Please provide an example if possible?

khalidali63
05-20-2003, 11:25 AM
If its the only comma you are worried about, that can be solved using
string.replace('character to be removed','character to be replaced with');

for a complext string parse,regExp could be the best solution.

http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/regexp.html#1193136

florida
05-20-2003, 11:26 AM
Thanks! That solved my problem.

pyro
05-20-2003, 11:36 AM
If you want, you can use this regexp to remove all non-numerical enteries.

string.replace(/\D/g,'');