flex之StringValidator

<?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">
	<s:layout>
		<s:BasicLayout/>
	</s:layout>
	<fx:Script>
		<![CDATA[
			import mx.controls.Alert;
			import mx.events.ValidationResultEvent;
			protected function userNameValidator_validHandler(event:ValidationResultEvent):void
			{
				Alert.show("感谢您的输入");
			}
			protected function userNameValidator_invalidHandler(event:ValidationResultEvent):void
			{
				Alert.show("感输入的信息不正确,请重新输入");
			}
		]]>
	</fx:Script>
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
		<mx:StringValidator
			id="userNameValidator"
			enabled="true"
			source="{username}"
			property="text"
			required="true"
			requiredFieldError="名称是必须要输入的"
			maxLength="6"
			tooLongError="您输入的名字不能超过6个字符"
			minLength="1"
			tooShortError="您输入的名字不能少于1个字符"
			listener="{errorInfoUsername}"
			valid="userNameValidator_validHandler(event)"
			invalid="userNameValidator_invalidHandler(event)"
			trigger="{submitButton}"
			triggerEvent="click"
			/>
	</fx:Declarations>
	
	<s:VGroup horizontalCenter="0" verticalCenter="0">
		<s:Label text="请输入名户名:"/>
		<s:TextInput id="username"/>
		<s:Label text="用来显示用户名输入框的错误信息的输入框"/>
		<s:TextInput id="errorInfoUsername"/>
		<s:Button label="Submit" id="submitButton"/>
	</s:VGroup>
</s:Application>

你可能感兴趣的:(Flex)