Actionscript 3 我们如何在flex中使用比较验证器
Flex中有比较验证器吗?我找了,但找不到。有没有像比较验证器这样的验证器 我的示例是如何使用flex validator检查密码和确认密码是否相同Actionscript 3 我们如何在flex中使用比较验证器,actionscript-3,apache-flex,flex4,Actionscript 3,Apache Flex,Flex4,Flex中有比较验证器吗?我找了,但找不到。有没有像比较验证器这样的验证器 我的示例是如何使用flex validator检查密码和确认密码是否相同 <s:TextInput id="password" width="218" textAlign="left" contentBackgroundColor="#FFFFFF"/> <s:TextInput id="confirmpassword" width="218" textAlign="left" contentBackg
<s:TextInput id="password" width="218" textAlign="left" contentBackgroundColor="#FFFFFF"/>
<s:TextInput id="confirmpassword" width="218" textAlign="left" contentBackgroundColor="#FFFFFF"/>
具有以下两个电子邮件字段,首先我们定义了一个标准电子邮件验证程序,对于确认,我们定义了一个附加在答案末尾的自定义电子邮件验证程序
<mx:HBox
verticalAlign = "middle"
color = "#101010">
<mx:Label
text = "E-Mail Address:"
width = "120"/>
<mx:TextInput
id = "txtEmail"
width = "220"/>
</mx:HBox>
<mx:HBox
verticalAlign = "middle"
color = "#101010">
<mx:Text
text = "Rewrite E-Mail Address:"
width = "120"/>
<mx:TextInput
id = "txtEmail2"
width = "220"/>
</mx:HBox>
如果您需要手动检查表单中的验证器。例如,在提交注册内容之前,请使用以下方法
public function isValid():Boolean
{
var validators:Array = [valEmail, valEmail2];
var validatorErrorArray:Array = Validator.validateAll(validators);;
var isValidForm:Boolean = validatorErrorArray.length == 0;
return isValidForm;
}
你能说得更清楚些吗?有几个flex验证器,您也可以创建自己的。。请举例说明你想要什么achieve@AdrianPirvulescu请检查上面的示例。我没有得到它,还是您只是在寻找
==
?flex中没有比较验证器。有没有这样的验证器好吧,现在我明白你的意思了。看起来您需要的是一个字符串验证器,用于将键入的文本与给定的字符串进行匹配。现在就写答案…:)
package validators
{
import mx.validators.ValidationResult;
import mx.validators.Validator;
public class EmailConfirmationValidator extends Validator
{
public var confirmationSource: Object;
public var confirmationProperty: String;
public function EmailConfirmationValidator()
{
super();
}
// Define the doValidation() method.
override protected function doValidation(value:Object):Array
{
// Call base class doValidation().
var results:Array = super.doValidation(value);
if (value.text != value.confirmation)
{
results.push(new ValidationResult(true, null, "Mismatch",
"Emails do not match!"));
}
return results;
}
/**
* @private
* Grabs the data for the confirmation password from its different sources
* if its there and bundles it to be processed by the doValidation routine.
*/
override protected function getValueFromSource():Object
{
var value:Object = {};
value.text = super.getValueFromSource();
if (confirmationSource && confirmationProperty)
{
value.confirmation = confirmationSource[confirmationProperty];
}
return value;
}
}
}
public function isValid():Boolean
{
var validators:Array = [valEmail, valEmail2];
var validatorErrorArray:Array = Validator.validateAll(validators);;
var isValidForm:Boolean = validatorErrorArray.length == 0;
return isValidForm;
}