Determining whether a string contains a valid email address format : Email Address « Regular Expressions « Flash / Flex / ActionScript






Determining whether a string contains a valid email address format

 

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){

        var sEmail:String = new String("someone@someserver.com");
        var bValidEmail:Boolean = true;
        var nAmpIndex:int = sEmail.indexOf("@");
        var nDotIndex:int = sEmail.lastIndexOf(".");
        if(nAmpIndex == -1 || nDotIndex == -1) {
          bValidEmail = false;
        }
        if(!(nAmpIndex > 0)) {
          bValidEmail = false;
        }
          if(!(nDotIndex > nAmpIndex)) {
        bValidEmail = false;
        }
        if(!(nDotIndex < sEmail.length - 1) || !(nDotIndex > nAmpIndex + 1)) {
          bValidEmail = false;
        }
        trace(bValidEmail);
        
    }
  }
}

        








Related examples in the same category

1.Using a regular expression to determine whether a string contains a valid email address format