2 Replies Latest reply on Nov 18, 2010 11:33 AM by Hosseinrostamzadeh

    How to restricting user input to numbers/extracts only numbers

    Hosseinrostamzadeh

      qst1- I use a  text input(a flash-component ) which the user will enter only numbers in it (both integers and floating point numbers) but not any other symbols.

      This code


        on keyDown me

      if ("1234567890.-") contains the key or the key = backSpace or the key = Tab or the keyCode =123 or the keyCode = 124 then
          pass
        else
          stopEvent
        end if
       
      end

       

       

      works properly when I use it with old style text Fields in director.It does not however work with new style flash component(text input).

       

       

      qst 2- And possibly very simple problem:

       

      I have an other text field which the user will enter numbers(both integers and floating point number) separated with comma(,).Then after finishing the presses button to calculate some math operation on them.

      What I need is to access only numbers (and not commas) in a list then do some advanced calculation on these numbers.

      How can I write a piece of code to do this?

       

      My own code


      repeat with i =0 to nPoints-1
          xList.append(float(xTmp.char[2*i+1]))
         end repeat

       

      (where it picks up odd number(2*i +1) entries(for ex. 1. 3. 5. ..., because I know that users has to start with the first number in position 1 then separate it with comma then second number gets 3. position,....)

       

      As told it does the job only if the user writes integers and the code does not work when the user enters decimal numbers.

       

       

      Any suggestion/help is appreciated?

      Best regards!

      HR