使用Validators.validateAll()方法同时验证多个输入

实例演示了当用户点击button时,如何使用Validators.validateAll()方法同时验证多个输入的正确和StringValidator的基本用法
代码在这里:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white" creationComplete="initApp()">

<mx:Style>
.errorTip
{
fontSize: 12;
}
</mx:Style>
<mx:Script>
<![CDATA[
import mx.events.ValidationResultEvent;
import mx.controls.Alert;
import mx.validators.Validator;

private var myValidators:Array;


private function initApp():void {
myValidators = [valid1, valid2];
}

private function clickHandler():void {
var errors:Array = Validator.validateAll(myValidators);
if (errors.length == 0) {
Alert.show("Looks valid to me.", "SUCCESS");
}
}
]]>
</mx:Script>

<mx:StringValidator id="valid1" source="{ti1}" property="text" minLength="4" maxLength="6" tooShortError="太少了吧" tooLongError="太多了吧" />
<mx:StringValidator id="valid2" source="{ti2}" property="text" minLength="4" maxLength="6" />
<mx:Label text="最少4个字符,最多6个字符,谢谢!" fontSize="12"/>

<mx:TextInput id="ti1" />
<mx:TextInput id="ti2" />

<mx:Button label="validate" click="clickHandler()" />

</mx:Application>

你可能感兴趣的:(xml,Adobe)