3 Replies Latest reply on May 27, 2006 2:12 AM by poonamsheth

    DateValidation through actionscript

      I want an application to support a number of different date formats ('yyyy:mm d,mm/dd/yyyy,dd/mm/yyyy etc) I would like to just create a DateValidator and validate strings in a text input but I don't seem to be able to do this by saying new DateValidator. Is there another way to set the properties on this class/object?
        • 1. Re: DateValidation through actionscript
          GordonSmith Level 4
          You should be able to create a DateValidator programmatically by importing mx.validators.DateValidator and doing

          var dateValidator:DateValidator = new DateValidator();
          dateValidator.inputFormat = "MM/DD/YYYY";

          If you're not able to do this, please post the code and what error you are getting.
          • 2. Re: DateValidation through actionscript
            rodneyjlucas Level 1
            Thanks for your reply,

            my apologies for not being more detailed in the original question. I think I started out with two problems

            1. Declaring/initializing DateValidator
            I was getting the following error.

            A class's instance variables may only be initialized to compile-time constant expressions.

            I had this as a global var...ie <mx:Script>var myDateValidator = new DateValidator</mx:Script>. I placed this in a my init function and it was fine.

            2. calling Validation method
            I am not sure how/what to call on my new object. In the past I could use the static method isValid(). This worked great for the mxml based root component. Now I need to call a method for myDateValidator but this won't work with the static method right. I am trying to use it but it always finds the date valid. My guess is that I am calling the wrong function ?

            • 3. Re: DateValidation through actionscript
              poonamsheth Level 1
              hey freind i have a example for date formatting as well it validates it
              <?xml version="1.0" encoding="utf-8"?>
              <!-- Simple example to demonstrate the Formatter. -->
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" backgroundColor="#FFFFFF">


              import mx.events.ValidationResultEvent;
              private var vResult:ValidationResultEvent;

              // Event handler to validate and format input.
              private function Format():void
              vResult = dateVal.validate();
              if (vResult.type==ValidationResultEvent.VALID) {

              else {
              formattedDate.text= "";

              <mx ateFormatter id="dateFormatter" formatString="month: MM, day: DD, year: YYYY"/>

              <mx ateValidator id="dateVal" source="{dob}" property="text" inputFormat="mm/dd/yyyy"/>

              <mx anel title="Formatter Example using the DateFormatter class" width="75%" height="75%"
              paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">

              <mx:Label text="Enter date (mm/dd/yyyy):"/>
              <mx:TextInput id="dob" text="" width="50%"/>

              <mx:Button label="Validate and Format" click="Format();"/>
              <mx:TextInput id="formattedDate" editable="false" width="50%"/>

              </mx anel>