<?xml version="1.0" encoding="utf-8"?>
<!-- Simple example to demonstrate StringValidator. -->
<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">
<fx:Script>
import mx.controls.Alert;
</fx:Script>
<fx:Declarations>
<mx:StringValidator source="{fname}" property="text"
tooShortError="This string is shorter than the minimum allowed length of 4. "
tooLongError="This string is longer than the maximum allowed length of 20."
minLength="4" maxLength="20"
trigger="{myButton}" triggerEvent="click"
valid="Alert.show('Validation Succeeded!');"
invalid="Alert.show('Validation Failed!');"/>
</fx:Declarations>
<s:Panel title="StringValidator Example"
width="75%" height="75%"
horizontalCenter="0" verticalCenter="0">
<mx:Form left="10" right="10" top="10" bottom="10">
<mx:FormItem label="Enter a name between 4 and 20 characters: ">
<s:TextInput id="fname" width="100%"/>
</mx:FormItem>
<mx:FormItem >
<s:Button id="myButton" label="Validate" />
</mx:FormItem>
</mx:Form>
</s:Panel>
</s:Application>
StringValidator 验证信息
最新推荐文章于 2022-12-04 15:48:38 发布