4 Replies Latest reply on May 20, 2009 5:01 PM by Francisc

    NumberValidator

    Francisc Level 3

      Hello!

       

      I have the following validator and the TextInput it validates:

       

       

      <mx:NumberValidator id="myValidator" source="{myNumericInput}" property="text"

           domain="real" triggerEvent=""

           required="true" requiredFieldError="Required field."

           minValue="0" lowerThanMinError="Must be higher or equal to 0."

           maxValue="5e-8" exceedsMaxError="Must be lower or equal to 5e-8"/>

       

      <mx:TextInput id="myNumericInput" restrict="0-9.eE\-"/>

       

       

      The TextInput allows only the follwing characters: "0-9" (all numbers), "e" or "E", dot and minus (dash).

      The validator allows only numbers between 0 and 5e-8 (which is 0.00000005).

      All is ok as long as the value 0.00000005 (or lower) is entered, however if I enter 5e-8 it will invalidate it saying there is an invalid character, probably letter "e". How can I have it allow "e" or "E" please? It seems to know what 5e-8 is as it limits the maximum value to that.

       

      Thank you!

       

      P.S. The synthax highlighter is uselss.

        • 1. Re: NumberValidator
          _Natasha_ Level 4

          Hi,

          the error is written on validation: "The input contains invalid characters" (invalidCharError)

           

          By default "e" and "E" are not supported by this validator. See source and you understand it (flex is open source!).

          If you want supporting scientific notaion you should extend NumberValidator.

          • 2. Re: NumberValidator
            Francisc Level 3

            Yeah, I know that, but why does it accept and correctly evaluate inputs with:

             

            maxValue="5e-8" exceedsMaxError="Must be lower or equal to 5e-8" - works!

             

            But does not accept such values? It's a bit odd.

            With the validator statement above i can enter 0.00000005 and it will be valid, but I cannot enter 5e-8 which is equal the the first number and is also in the maxValue property.

            • 3. Re: NumberValidator
              _Natasha_ Level 4

              Reading NumberValidator.as

               

              var maxValue:Number = Number(validator.maxValue); // this way 1e-5 is allowed and parsed to real value.

               

              In function validateNumber(...) value first checked to be a number. And this checking is not Number(value) - it's not always correct (as an example 5ff can be parsed as 5). So checking verify all characters in string representation (even it is a number!). An at that moment e is an invalid character.

              • 4. Re: NumberValidator
                Francisc Level 3

                Ah, should of thought about looking in the class for the validator.

                In my oppinion this is a bug of the NumberValidator.

                 

                Thank you, Natasha!