topical media & game development
professional-flex-code-15-PasswordValidator.ax
professional-flex-code-15-PasswordValidator.ax
[swf]
flex
package
{
/*
Authored by Rich Tretola
*/
import mx.validators.Validator;
import mx.validators.ValidationResult;
public class @ax-professional-flex-code-15-PasswordValidator extends Validator {
private var results:Array;
public function @ax-professional-flex-code-15-PasswordValidator() {
super();
}
// Override the doValidation() method.
override protected function doValidation(value:Object):Array {
results = [];
// Call super's doValidation().
results = super.doValidation(value);
// Return if super's doValidation contains errors (required would be an example).
if (results.length > 0){
return results;
}
// Check for min length
var dataString:String = String(value);
if (dataString.length < 6){
results.push(new ValidationResult(true, null, "Short", "Password must be at least 6 characters."));
return results;
}
// Check for max length (this can be set in the text component's maxChars property).
if (dataString.length > 10){
results.push(new ValidationResult(true, null, "Long", "Password must be no larger than 10 characters."));
return results;
}
// Check for at least 1 upper case letter.
if (dataString.search("[A-Z]")<0) {
results.push(new ValidationResult(true, null, "Upper", "Passwords must contain at least one upper case letter."));
return results;
}
// Check for at least 1 lower case letter.
if (dataString.search("[a-z]")<0) {
results.push(new ValidationResult(true, null, "Lower", "Passwords must contain at lease one lower case letter."));
return results;
}
// Check for at least 1 number.
if (dataString.search("[0-9]")<0) {
results.push(new ValidationResult(true, null, "Number", "Passwords must contain at least one number."));
return results;
}
return results;
}
}
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.