Using ActionScript to validate Email
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
import mx.validators.EmailValidator;
import mx.validators.StringValidator;
import mx.controls.Alert;
import mx.events.ValidationResultEvent;
public var emailVal:EmailValidator = new EmailValidator();
public var stringVal:StringValidator = new StringValidator();
public function validateForm():void
{
var valResult:ValidationResultEvent;
stringVal.source = username;
stringVal.property = "text";
stringVal.minLength = 10;
emailVal.source = email;
emailVal.property = "text";
valResult = emailVal.validate();
if(valResult.type == "invalid"){
Alert.show("Invalid Email");
}
valResult = stringVal.validate();
if(valResult.type == "invalid"){
Alert.show("Invalid Username");
}
}
</mx:Script>
<mx:Text text="Email:" />
<mx:TextInput id="email" />
<mx:Text text="Enter your username:" />
<mx:TextInput id="username" />
<mx:Button label="Submit" id="submitButton" click="validateForm()" />
</mx:Application>
Related examples in the same category