flex验证之StringValidator

StringValidator主要用来验证输入字符串(必填,最少字符,最多字符),集成Validator
trigger:表示触发验证的源
triggerEvent:表示触发验证的源的事件


<?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:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
		<mx:StringValidator
			source="{username}"
			property="text"
			minLength="3"
			maxLength="20"
			required="true"
			trigger="{submitButton}"
			triggerEvent="click"
			tooShortError="最少需要输入三个字符"
			tooLongError="最多需要20个字符"
			requiredFieldError="必须输入这个输入框"
			>
		</mx:StringValidator>
	</fx:Declarations>
	<s:VGroup horizontalCenter="0" verticalCenter="0">
		<s:Label text="Enter your username:"/>
		<s:TextInput id="username"/>
		<s:Button label="submit" id="submitButton"/>
	</s:VGroup>
</s:Application>

你可能感兴趣的:(Flex,StringValidator)