Skip to main content
rafa@mediatech
Inspiring
October 13, 2010
Answered

Remove commas (,) from user entered numbers into a field

  • October 13, 2010
  • 2 replies
  • 3215 views

Hi everyone,

How can I filter out commas from a number entered by a user into a input text field? I am trying to do calculations with those numbers entered, but if the user enters a comma, i get "NaN" (not a number) as the result of what the user entered.

I could restrict the user from entering commas into the fields (I am already restriciting entering letters and periods), but it would be nice if the user can still use commas.

the code I have so far is:

        q4input = q4_mc.q4_ans.text;    

     q4_preCalc = (Number(q4input)*1000);     
     trace(q4_preCalc);

thank you for your help in advance.

Rafael.

This topic has been closed for replies.
Correct answer Andrei1-bKoviI

Try:

q4input = q4_mc.q4_ans.text.replace(",", "");

2 replies

October 13, 2010

If commas give error , then this should work I think:

q4input = q4_mc.q4_ans.text.replace(",", ".");

Andrei1-bKoviICorrect answer
Inspiring
October 13, 2010

Try:

q4input = q4_mc.q4_ans.text.replace(",", "");

rafa@mediatech
Inspiring
October 13, 2010

Andrei1,

Thank you, that worked perfectly.

Rafael.

Inspiring
October 14, 2010

You are welcome.