自定义二次确认验证控件

最近用flex,在验证的时候发现没有确认比较验证控件,在网上找一下发现泥水作坊的博客不错,借鉴一下高人的代码。记录下来,以防忘记
定义一个验证控件,继承了Validator

package confirm
{
import mx.validators.ValidationResult;
import mx.validators.Validator;

public class ConfirmVlidator extends Validator
{
public function ConfirmVlidator()
{
super();
}

public var messages : Array;
public var compareError : String;
public var compareSource : Object;
public var compareProperty : String;

override protected function doValidation(value : Object) : Array
{
messages = [];
messages = super.doValidation(value);
if(messages.length > 0)
{
return messages;
}
if(source[property] != compareSource[compareProperty])
{
messages.push(new ValidationResult(true,null,null,compareError));
}
return messages;
}
}
}

引用mxml文件

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
xmlns:gshzhou="confirm.*">
<mx:TextInput x="172" y="93" id="password"/>
<mx:TextInput x="172" y="139" id="confirmPassword"/>
<mx:Button x="218" y="224" id="testButton" label="test"/>

<gshzhou:ConfirmVlidator source="{confirmPassword}" property="text" required="true" requiredFieldError="必须输入"
compareSource="{password}" compareProperty="text" compareError="2次输入的不一致"
trigger="{testButton}" triggerEvent="click">

</gshzhou:ConfirmVlidator>
</mx:Application>


[flash=200,200]

[/flash]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值