Created
September 7, 2012 05:40
-
-
Save tvdsluijs/3663508 to your computer and use it in GitHub Desktop.
Flex Password match check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<validator:StringMatchValidator id="passwordMatchValidator" | |
source="{password2}" | |
property="text" | |
matches="{password1.text}" /> | |
//And just add this class to your project for the actual checking of the password match. | |
package validator | |
{ | |
import mx.validators.ValidationResult; | |
import mx.validators.Validator; | |
public class StringMatchValidator extends Validator { | |
// Define Array for the return value of doValidation(). | |
private var results:Array; | |
// Define compare string | |
private var _matches : String = ""; | |
// Define mismatch error messsage | |
private var _mismatchError : String = "Password Dosen't match Retype!"; | |
// Constructor. | |
public function StringMatchValidator() { | |
super(); | |
} | |
public function set matches (s : String) : void { | |
_matches = s; | |
} | |
public function set mismatchError (s : String) : void { | |
_mismatchError = s; | |
} | |
// Define the doValidation() method. | |
override protected function doValidation(value:Object):Array { | |
//var pwd: Password = value as Password; | |
var s1: String = _matches; | |
var s2: String = source.text; | |
results = []; | |
results = super.doValidation(value); | |
// Return if there are errors. | |
if (results.length > 0) | |
return results; | |
if(s1 == s2) | |
{ | |
return results; | |
} | |
else | |
{ | |
results.push(new ValidationResult(true, null, "Mismatch", _mismatchError)); | |
return results; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment