ITeye博客

flex4.5 validator 验证正则表达式的使用

wentry · 2011-09-24 20:56 · flex开发 · Web前端 · Markdown

在正则表达式中,含有大括号时,验证不通过,需自定义一个字符串值为正则表达式的内容。 验证通过时才执行操作。 valid="keyPhone_A_Button_clickHandler(event)" 为验证通过时触发的事件, 当然也有验证不通过时触发的事件了。 text="@{keyPhoneVO.phoneNumber_Text}" 是进行数据双向绑定的,测试时可以先去掉。

mxml文件:

<fx:Declarations>
	<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	<mx:RegExpValidator source="{phoneNumber_Text}" 
						property="text" 
						expression="{ValidateVO.phoneValidat}"
						trigger="{keyPhone_A_Button}"
						valid="keyPhone_A_Button_clickHandler(event)"
						triggerEvent="click"
						noMatchError="请输入正确的手机号"
						required="true" 
						requiredFieldError="新增时必须输入手机号"/>
</fx:Declarations>


		<s:TextInput id="phoneNumber_Text" x="66" y="35" contentBackgroundColor="#FFFDFD"
					 text="@{keyPhoneVO.phoneNumber_Text}"/>

在ValidateVO. as文件中,定义正则表达式。直接在expression中写正则表达式时,编译无法识别,按照官网介绍的方法,我们还是自己定义一个字符串好了。 // 电信手机号验证表达式 public static var phoneValidat:String = "^1(3|5|8)\d{8}$";

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。