package core.util
{
import mx.validators.ValidationResult;
import mx.validators.Validator;
public class CompareValidator extends Validator
{
public var valueToCompare:Object;
public var errorMessage:String = "Value does not match.";
public function CompareValidator()
{
super();
}
override protected function doValidation(value:Object):Array {
var results:Array = [];
var srcVal:Object = this.getValueFromSource();
if (srcVal != valueToCompare) {
results.push(new ValidationResult(true, null, "Match",errorMessage));
}
return results;
}
}
}
The MXML looks like this:
<coreutil:CompareValidator
id="comparePasswords"
source="{password2}"
property="text"
valueToCompare="{password.text}"
errorMessage="Passwords do not match."
/>
1 comment:
very simple and good example.
Thanks,
Talib Aziz
Post a Comment