1 Reply Latest reply on Jul 5, 2009 9:31 PM by Madhav Subedi

    How to use EmailValidator to validate a simple String instead of TextInput

    haibin_sh

      Hi,

       

      I'd like to use EmailValidator to validate if a string is a valid email address. But I got an exception when I tried to set source to the string.

       

       

       

       

      var tmp:String = asdf@asdf.com;

       

       

       

      var emailVal:EmailValidator = new EmailValidator();

      emailVal.source = tmp;

       

      I know we usually do

       

      emailVal.source = new TextInput()

      emailVal.property = "text"

       

      But here I want to simply validate a string. How can I do it?

       

       

      Regards,

      Haibin

        • 1. Re: How to use EmailValidator to validate a simple String instead of TextInput
          Madhav Subedi Level 4

          use validate() method, which returns the validationresultevent; now you can check the type property of that event.

           

          code:

           

                         var tmp:String = "asdf@asdf.com";

                          var emailVal:EmailValidator = new EmailValidator();
                          var vr:ValidationResultEvent = emailVal.validate(tmp);
                          if(vr.type == ValidationResultEvent.VALID)
                              ;//it is valid
                          else
                              ;//it is invalid