5 Replies Latest reply on Feb 4, 2011 6:13 AM by Jerry62712

    How do I validate a phone number?

    Jerry62712 Level 1

      I have a TextInput control to hold a phone number.  It can be blank unless one of the other controls is filled in.  I thought I would invoke the validator in that case in Actionscript.  But it doesn't seem to work.


      The control:

                      <DHSCntl:rightLabel id="dtPhone"
                          label="Res. Prov. Phone:"
                          <mx:TextInput id="RECPROVIDERPHONE"


      The validator:

      <mx:PhoneNumberValidator id="dtRecProviderPhoneVal"
          allowedFormatChars="()- ."
          wrongLengthError="{phoneLengthWarning}" />


      The code:

              if (!compDT.RECPROVIDERPHONE.validateNow())
                  var phoneErr:String = "Provider Phone format is invalid";
                  err += "\n";
                  err += phoneErr;
                  err += "\n";


      Even with a valid phone number "(217) 555-1212", it returns it being invalid.

        • 1. Re: How do I validate a phone number?
          UbuntuPenguin Level 4

          I believe you can just pass the phone number to the phone number validator, and if the validation

          result array has a length greater than zero , you set that to the error string of the text input.

          • 2. Re: How do I validate a phone number?
            Jerry62712 Level 1

            How would you do that?

            • 3. Re: How do I validate a phone number?
              _spoboyle Level 4



              http://www.adobe.com/devnet/flex/videotraining/_jcr_content/bodycontent1/modal_33.content. html


              did it say invalid characters? you didn't add the space character to your allowed characters list.


              <?xml version="1.0" encoding="utf-8"?>

              <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                          import mx.events.ValidationResultEvent;
                          protected function clickHandler():void
                              var event:ValidationResultEvent = phoneValidator.validate();
                              if (event.type == ValidationResultEvent.VALID)


                      <mx:PhoneNumberValidator id="phoneValidator"
                                               allowedFormatChars="()-. "
                  <s:TextInput id="phoneNumber"/>
                  <s:Button label="submit" click="clickHandler()"/>
              • 4. Re: How do I validate a phone number?
                Jerry62712 Level 1

                Belated thanks (we were out yesterday).


                I'll be checking on the space this morning.  More later...

                • 5. Re: How do I validate a phone number?
                  Jerry62712 Level 1

                  The space was there.  I think it was the approach I was taking (validateNow()).  After I changed it to the way you suggested, it works.  Thanks for the time and for everyone else for the time to help a guy.