Hi Børre,

Many thanks for sharing the code. Exactly what I was after. Much appreciated!

Cheers
Steve



On 9/17/06, bgwessel <[EMAIL PROTECTED]> wrote:

Hi

When I read your message I found that I had the same need, so here it


is :)

package com.mycomp.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 are not equal";

/**
* 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 in both mxml and AS3, just include the textinput
fields; password and password2:


<validator:PasswordValidator id="pwdV" source="{password2}"
property="text" pwdToCheck="{password.text}"/>

var pwdValidator:PasswordValidator = new PasswordValidator();
pwdValidator.listener = password2;
pwdValidator.pwdToCheck = password.text;
pwdValidator.validate(password2.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





SPONSORED LINKS
Software development tool Software development Software development services
Home design software Software development company

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___

Reply via email to