<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.ValidationResultEvent;
import mx.validators.EmailValidator;
import mx.validators.StringValidator;
import mx.validators.ValidationResult;
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=6;
emailVal.source = email;
emailVal.property = "text";
valResult = emailVal.validate();
if(valResult.type == "invalid" )
{
Alert.show("Please fix your Email address.");
}
else
{
valResult = stringVal.validate();
if(valResult.type == "invalid")
{
Alert.show("Please fix your Username.");
}
}
}
]]>
</fx:Script>
<s:VGroup horizontalCenter="0" verticalCenter="0">
<s:Label text="Email:"/>
<s:TextInput id="email"/>
<s:Label text="Enter your username:"/>
<s:TextInput id="username"/>
<s:Button label="提交" id="submitButton" click="validateForm()"/>
</s:VGroup>
</s:Application>