Hi
When I read your message I found that I had the same need, so here
it is :)
package com.yourcompany.validator
{
import mx.validators.Validator;
import mx.validators.ValidationResult;
public class PasswordValidator extends Validator
{
/**
* Constructor.
*/
public function PasswordValidator()
{
super();
}
/**
* The password the check against.
*/
public var pwdToCheck:String;
/**
* Convenience method for calling the validator from
custom classes.
*/
public static function validatePassword
(validator:PasswordValidator,
value:Object,
baseField:String = null):Array
{
var results:Array = [];
var val:String = value != null ? String
(value) : "";
if(val != validator.pwdToCheck)
{
results.push(new ValidationResult(
true, baseField,
"notEqual", validator.notEqualError));
return results;
}
return results;
}
/**
* Error message when the passwords are not equal.
*
* @default "Too many at characters in your email
address."
*/
public var notEqualError:String = "Passwords do not
match";
/**
* Override of the base class <code>doValidation()
</code> method
* to validate two password fields.
*/
override protected function doValidation
(value:Object):Array
{
var results:Array = super.doValidation
(value);
// Return if there are errors
// or if the required property is set to
false and length is 0.
var val:String = value ? String(value) : "";
if (results.length > 0 || ((val.length == 0)
&& !required))
return results;
else
return PasswordValidator.validatePassword
(this, value, null);
}
}
}
It can be used from both mxml and AS3, just include two textinput
fields, password and password2.
<validator:PasswordValidator id="pwdV" source="{password2}"
property="text" pwdToCheck="{password.text}"/>
Regards
Børre
--- In [email protected], "Steve Gilchrist" <[EMAIL PROTECTED]>
wrote:
>
> Is there a pre-existing validator for checking that two fields
match eg.,
> password and confirmPassword form fields?
>
> I would prefer not to have an alert popup but the check done in a
consistent
> way with some other validators. Anyone built one of these already?
>
> Thanks
> Steve
>
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/flexcoders/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/