7 Replies Latest reply on Feb 5, 2008 7:29 AM by kglad

    Validate an email address

    SteveH59 Level 1
      Hello

      I am using this to validate email addresses and it does not seem to work:

      } else if (!email_txt.length || email_txt.indexOf("@") == -1 || email_txt.indexOf(".") == -1) {
      status_txt.text = "Invalid Email.";

      I would, in any case, prefer to use the following server script for validation purposes:

      <%
      'Email
      re.Pattern = "^\w+@\w+\.\w+"
      If Not re.Test(email) Then
      errorArray(1) = "red"
      ErrorMsg = ErrorMsg & "<center>Please type in a valid email address</center>"
      end if
      %>

      If I use this server script, how do I begin to show it in my movie, please? What Action Script do I use to 'pull it in' from the server and show it?

      Many thanks

      Steve
        • 1. Re: Validate an email address
          kglad Adobe Community Professional & MVP
          you need to use as3 to use regular expressions. (and use the attach code option to display code in this forum.)
          • 2. Re: Validate an email address
            Level 7
            Here's an email validation class I use:


            /**
            * EmailValidator<br>
            * (c) 2006 blurredistinction, LLC<br>
            * www.blurredistinction.com
            * <p>
            * by Dave Mennenoh<br>
            * dave@blurredistinction.com
            * <p>
            * Allows email addresses to be easily checked for validity using current
            verification rules.
            * <p>
            * Usage: var emv:EmailValidator = new EmailValidator();<br>
            * var valid = emv.validate("dave@blurredistinction.com");
            */
            class com.blurredistinction.EmailValidator {

            //ranges of valid ASCII values for email addresses
            private var validASCII:Array = [[43, 43], [45, 46], [48, 57], [61, 61],
            [65, 90], [94, 95], [97, 123], [125, 126]];


            function EmailValidator () {}


            /**
            * Checks an email address for validity.
            *
            * @param email Email string to be checked for validity
            * @return Boolean - True if valid
            */
            public function validate (email:String):Boolean {
            //split email into local and domain portions
            var localDom:Array = email.split ("@");
            //
            //there can be only one @ sign - and there has to be one
            //and there must be something before the @
            if ((localDom.length != 2) || (localDom[0].length < 1)) {
            return false;
            }
            //local portion can't start or end with a .
            if ((localDom[0].charAt(0) == ".") || (localDom[0].charAt
            (localDom[0].length - 1) == ".")) {
            return false;
            }
            //split the domain portion into domain name and extension
            var domExtension:Array = localDom[1].split (".");
            //
            //domain must contain at least one .
            if(domExtension.length < 2){
            return false;
            }
            //
            //domain can't start with a .
            if(domExtension[0].length == 0){
            return false;
            }
            //
            //there can be multiple .'s in the domain portion so use the last item in
            the array
            //extension length must be between 2 and 4 characters
            if (domExtension[domExtension.length - 1].length < 2 ||
            domExtension[domExtension.length - 1].length > 4) {
            return false;
            }
            //finally check the local portion & domain for invalid chars
            if ((!checkString (localDom[0])) || (!checkString (localDom[1]))) {
            return false;
            }
            return true;
            }



            //------------------------ PRIVATE ---------------------------


            /**
            * Checks each character in the string to see if it's in the range of valid
            ascii
            *
            * @param theString String to be validated
            * @return True if each character is in a valid range
            */
            private function checkString (theString:String):Boolean {
            var sl = theString.length;
            var ind:Number;
            for (ind = 0; ind < sl; ind++) {
            if (!isValidASCII (theString.charCodeAt (ind))) {
            return false;
            }
            }
            return true;
            }

            /**
            * See if the input character falls in the valid range of valid ascii chars
            *
            * @param theChar Single character passed in from checkString()
            * @return True if individual char is in a valid range
            */
            private function isValidASCII (theChar:Number):Boolean {
            var ind:Number;
            for (ind = 0; ind < validASCII.length; ind++) {
            if ((theChar >= validASCII[ind][0]) && (theChar <= validASCII[ind][1])) {
            return true;
            }
            }
            return false;
            }
            }


            HTH


            --
            Dave -
            Head Developer
            http://www.blurredistinction.com
            Adobe Community Expert
            http://www.adobe.com/communities/experts/


            • 3. Re: Validate an email address
              SteveH59 Level 1
              Hello kglad

              Here's the brief ASP I am using:

              • 4. Re: Validate an email address
                SteveH59 Level 1
                Very many thanks, Dave.

                That looks heavy!

                Can I ask about your AS? Do you have a dymanic text box to show any errors/non-errors?

                Thanks.

                Steve
                • 5. Re: Validate an email address
                  kglad Adobe Community Professional & MVP
                  if you're using asp for the regular expressions, no problem.
                  • 6. Re: Validate an email address
                    SteveH59 Level 1
                    Hello kglad again

                    I'm probably not explaining myself very well. I use the following validation (please see attached code) to check a number of fields in an HTML-based form I have. The validation script for all fields works for this HTML form. What I would like to do is use the validation script with my Flash-based form.

                    However, what I do not know is how to display these various error messages in Flash. I would prefer a simple dynamic text box alongside the form itself, but

                    1) Do I use Response.Write to pass these errors to Flash and, if so, what about the Action Script side of things?

                    2) Does ASP pass its Response.Write statements automatically to the 'waiting' dynamic text box meaning I do not need any Action Script?

                    Many thanks again.

                    Steve

                    • 7. Re: Validate an email address
                      kglad Adobe Community Professional & MVP
                      1. yes
                      2. no

                      1. use the loadvars class to send data to your asp file and receive data from your asp file. you can check any php email tutorial for info on how to do this.

                      even though you're using asp and you're not sending email via asp, only validating, everything on the flash side is about the same.

                      flashgods.org has a faq section that has an php email tutorial that will walk you through.