Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Participant ,
Oct 13, 2010 Oct 13, 2010

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.

TOPICS
ActionScript
3.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Oct 13, 2010 Oct 13, 2010

Try:

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

Translate
LEGEND ,
Oct 13, 2010 Oct 13, 2010

Try:

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 13, 2010 Oct 13, 2010

Andrei1,

Thank you, that worked perfectly.

Rafael.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 13, 2010 Oct 13, 2010
LATEST

You are welcome.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 13, 2010 Oct 13, 2010

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

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines