4 Replies Latest reply on Jul 30, 2010 12:00 PM by LaRetta_1

    Validating Numeric Field

    GiovanniAndreani

      Title

      Validating Numeric Field

      Post

      Hello, I've created a number type field and specified in options –> validation that the data required would be strictly numeric only. I found I could enter that field via script and input a non-numeric character trough an input field from a custom dialog box! Is there anyway to avoid this? I have to be shore the user will input only numeric data.

      Using FM Pro 11 Advanced running on Mac Os 10.5

      Thank you in advance

      Giovanni

        • 1. Re: Validating Numeric Field
          philmodjunk

          What happens if you select the "validate always" option? Does that work for you?

          In your script, validation does not take place while the user enters data into a custom dialog's input fields, you can only test it after the fact and re-display the custom dialog if there was an input error, so you may want to simply modify your script to test the value yourself or design a input layout that is displayed as a pop-up window with the new window script step instead of a custom dialog.

          • 2. Re: Validating Numeric Field
            GiovanniAndreani

            Thank you PhilModjunk, if I select "validate always" that'll work, but I also need the user to insert a positive number only (and no zero), so I found out that using the "Sign" function will help validate the field even if "validate always" is not selected. Infact, it returns 1 only for a positive numeric character, any other character will return 0.

            Thank you for your help!

            • 3. Re: Validating Numeric Field
              LaRetta_1

              The problem with using Sign() by itself is that text is still allowed mixed with the numbers, including spaces.  Garbage, including invalid characters and carriage returns can also be pasted into the field mixed in with numbers and they will produce 1 for Sign().

              I would suggest you just remove the garbage by applying auto-enter calculation with:

              Filter ( Self ; "0123456789" )

              ... and use that in conjunction with Sign() as validation but I would specify the validation calculation as:  Sign ( Self ) or IsEmpty ( Self)

              Include decimal in the Filter() string if allowed (so User can type .34 if acceptable) and be sure (after returning to the auto-enter tab) to uncheck 'do not replace existing value ...).

              • 4. Re: Validating Numeric Field
                LaRetta_1

                It was early ... GetAsNumber ( Self ) to restrict from garbage and then your validation calc.