Announcement

Collapse
No announcement yet.

check if the input text is number or not

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • check if the input text is number or not

    I have a very simple question:
    I have 3 input objects in my first page of project
    thees inputs must include just numbers (and . for decimals). how can I manage that if the input texts was not numeric then a msg.box appear and if there was just number then jump to the next page. thanks for your helps

  • #2
    Hi you could try this example to get an idea
    Have a couple of different functions in Globals
    Check input box on key events also
    Cheers
    Input Only numbers.apz

    Comment


    • #3


      here an example

      input_only_number.zip

      Comment


      • #4
        Here's another example to use subclassing to real-time filter (before the characters are printed). This example also filters the comma and replaces it with a dot, as an example of what you can do. It uses the MemoryEx plugin and the (included in the example) windows.lh resident file.
        Attached Files
        Bas Groothedde
        Imagine Programming :: Blog

        AMS8 Plugins
        IMXLH Compiler

        Comment


        • #5
          Originally posted by colc View Post
          Hi you could try this example to get an idea
          Have a couple of different functions in Globals
          Check input box on key events also
          Cheers
          [ATTACH]n305315[/ATTACH]
          that was really useful, thanks.

          Comment


          • #6
            Originally posted by herrin View Post

            here an example

            [ATTACH]n305317[/ATTACH]
            thanks for your help.

            Comment


            • #7
              You can minimize overhead and do this quite effeciently by making use of the native Lua function: tonumber. By inverting its inherent logic, we can create a simple custom function that will detect for numbers (including the decimal point):

              Place this in Globals:
              Code:
              function numberRestrict(inputObject)
                   local inputString = Input.GetText(inputObject);
                   if inputString ~= "" then
                        if not tonumber(inputString) then
                             Dialog.Message("Input Error", "Invalid input detected.\r\nEnter numbers only.\r\n\r\nEg. 8, 6.5, etc ...");
                             Input.SetText(inputObject, "");
                             Application.ExitScript();
                        end
                   end
              end

              ... and this in the On Key event of your Input Object:
              Code:
              numberRestrict("Input1")
              Example attached. Modify according to your needs.
              Attached Files

              Comment


              • #8
                Originally posted by BioHazard View Post
                You can minimize overhead and do this quite effeciently by making use of the native Lua function: tonumber. By inverting its inherent logic, we can create a simple custom function that will detect for numbers (including the decimal point):

                Place this in Globals:
                Code:
                function numberRestrict(inputObject)
                local inputString = Input.GetText(inputObject);
                if inputString ~= "" then
                if not tonumber(inputString) then
                Dialog.Message("Input Error", "Invalid input detected.\r\nEnter numbers only.\r\n\r\nEg. 8, 6.5, etc ...");
                Input.SetText(inputObject, "");
                Application.ExitScript();
                end
                end
                end

                ... and this in the On Key event of your Input Object:
                Code:
                numberRestrict("Input1")
                Example attached. Modify according to your needs.
                Nice clean Solution BioHazard

                Comment

                Working...
                X