Flashr_logo

How To : Validate an Email with AS3

To validate an email in ActionScript create a new RegExp (regular expression) and use it's test method to see if the email matches the pattern. If it matches the method will return 'true', if not it will return 'false'.

var goodEmail:String = "agoodemailaddress@foo.com";
var badEmail:String = "abademailaddress@foo..com";
           
var regExp:RegExp = /([\w-\.] )@((?:[\w] \.) )([a-zA-Z]{2,4})/;
           
trace( "goodEmail is valid?", regExp.test( goodEmail) );
trace( "badEmail is valid?", regExp.test( badEmail) );