3 Replies Latest reply on May 16, 2010 11:22 AM by kglad

    email validation

    esco1313 Level 1

      Hey Guys!!

       

      Just one quick easy question ( i guess),

       

      i have this code and i want the email to be validated (right email format). If it's not, i want it to go play the error_clip... However, i dont know how to implement it...

       

      stop();
      System.useCodepage = true;
      send_btn.onRelease = function() {
          my_vars = new LoadVars();
          my_vars.sender = email_box.text;
          my_vars.subject = subject_box.text;
          my_vars.message = message_box.text;
          if (my_vars.sender != "" and my_vars.subject != "" and my_vars.message != "")  {
              my_vars.sendAndLoad("mailer.php", my_vars, "POST");
              gotoAndStop(2);
          } else {
              error_clip.gotoAndPlay(2);
          }
          my_vars.onLoad = function() {
              gotoAndStop(3);
          };
      };
      email_box.onSetFocus = subject_box.onSetFocus=message_box.onSetFocus=function () {
          if (error_clip._currentframe != 1) {
              error_clip.gotoAndPlay(6);
          }
      };

       

      What should i put and where??

       

      thx!

        • 1. Re: email validation
          kglad Adobe Community Professional & MVP

          you can use:

           

           


           

          stop();
          System.useCodepage = true;
          send_btn.onRelease = function() {

          if(validEmailF(email_box.text)){

              my_vars = new LoadVars();
              my_vars.sender = email_box.text;
              my_vars.subject = subject_box.text;
              my_vars.message = message_box.text;
              if (my_vars.sender != "" and my_vars.subject != "" and my_vars.message != "") and {
                  my_vars.sendAndLoad("mailer.php", my_vars, "POST");
                  gotoAndStop(2);
              } else {
                  error_clip.gotoAndPlay(2);
              }
              my_vars.onLoad = function() {
                  gotoAndStop(3);
              };

          } else {

          //not valid email.  do something.

          }

          };


          email_box.onSetFocus = subject_box.onSetFocus=message_box.onSetFocus=function () {
              if (error_clip._currentframe != 1) {
                  error_clip.gotoAndPlay(6);
              }
          };

           

          function validEmailF(email:String):Boolean {
              var at:String = "@";
              var dot:String = ".";
              var lat:Number = email.indexOf(at);
              var lemail:Number = email.length;
              var ldot:Number = email.indexOf(dot);
              if (email.indexOf(at) == -1) {
                  return false;
              }
              if (email.indexOf(at) == -1 || email.indexOf(at) == 0 || email.indexOf(at) == lemail) {
                  return false;
              }
              if (email.indexOf(dot) == -1 || email.indexOf(dot) == 0 || email.indexOf(dot) == lemail) {
                  return false;
              }
              if (email.indexOf(at, (lat+1)) != -1) {
                  return false;
              }
              if (email.substring(lat-1, lat) == dot || email.substring(lat+1, lat+2) == dot) {
                  return false;
              }
              if (email.indexOf(dot, (lat+2)) == -1) {
                  return false;
              }
              if (email.indexOf(" ") != -1) {
                  return false;
              }
              return true;
          }

          • 2. Re: email validation
            esco1313 Level 1

            bravo!

             

            you did it again!

             

            thx alot man

            • 3. Re: email validation
              kglad Adobe Community Professional & MVP

              you're welcome.