4 Replies Latest reply on Dec 21, 2009 4:40 AM by Francisc

    Flex Validation Examples

    KalavatiSingh Level 1


            My requirement is I need a TextFeild   that must validate the following conditions


      1) It should not be empty

      2)It should take only numeric input.

      3) The input to that textfeild must be in a range say between 100-200 only.

            The examples or documents that I have gone through on adobe  can fit for satisfying two conditions (1 & 2) but I donot find any example /documentation where all three conditions could be satisfeid.

              Kindly let me know how that can be acheived





      Kalavati Singh


        • 2. Re: Flex Validation Examples
          Francisc Level 3

          <mx:NumberValidator id="myNumValidator" source="{myTextInput}" property="text" triggerEvent="" domain="int" allowNegative="false"

                   required="true" requiredError="You must type in a number."

                   minValue="100" lowerThanMinError="Cannot be lower than 100."

                   maxValue="200" exceedsMaxError="Cannot be over 200."/>


          <mx:TextInput id="myTextInput" restrict="0-9"/>


          The above example only allows Integer numbers that are not negative. Also, only digits from 0 to 9 are allowed in the input.

          If you wanted real numbers and negative you would obviously set domain="real" and allowNegative="true" as well as the the TextInput property restrict="0-9.-" so that it allows "." and "-" as well.

          • 3. Re: Flex Validation Examples
            KalavatiSingh Level 1

            Hi M*A*S*H 4077,

                 Thank you for your response. I want to add one more point to this requirement say that texfeild1 should be always less than textfeild2.How  that can be acheived






            • 4. Re: Flex Validation Examples
              Francisc Level 3

              Instead of maxValue="200" you can write: maxValue="{textfeild2.value}" and this makes it automatically detect the value.

              Only problem is when the other field is null or 0.


              What is probably best is to do this programatically.

              For example after the users writes the text he presses a button which has a function associated with it, for example clickHandler(event).


              Inside that function, you should make the checking:


              private function clickHander(event:MouseEvent):void




                        textfeild1.errorString="This field cannot be greater than textfeild2";

                        //That will look exacty like the errors the Validators give you



                       // ALL IS OK, EXECUTE CODE.


              1 person found this helpful