You can do it using regex.
private function isValidPassword(value:String):Boolean
{
if(value.length < minLength)
return false;
var regexArray:Array = [/[A-Z]/, /\d/, /[a-z]/, /[^\w]/];
var flag:Boolean = true;
var result:Object;
for(var i:Number = 0; i < regexArray.length; i++)
{
result = RegExp(regexArray[i]).exec(value);
if(!result)
{
trace(value + " fails test " + i);
return false;
}
}
return true;
}
/A-Z/
checks for an upper case letter.
/a-z/
checks for a lower case letter.
/\d/
checks for a digit
/[^\w]/
checks for a non word character. Note that regex treats _ as a word character. Thus _ will not be counted as symbol.
Update: Add /[^\w]|_/
to the regex array to count _ as symbol.
Update: Here is a flex app using RegExpValidator
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
xmlns:local="*" creationComplete="create();">
<mx:TextInput id="textInput"/>
<mx:Button id="btn" label="Submit" click="validate();"/>
<mx:RegExpValidator id="reg1" source="{textInput}" expression="[a-z]"
noMatchError="At least one lower case char" invalid="onInvalid(event)"
property="text"/>
<mx:RegExpValidator id="reg2" source="{textInput}" expression="[A-Z]"
noMatchError="At least one upper case char" invalid="onInvalid(event)"
property="text"/>
<mx:RegExpValidator id="reg3" source="{textInput}" expression="\d"
noMatchError="At least one number" invalid="onInvalid(event)"
property="text"/>
<mx:RegExpValidator id="reg4" source="{textInput}" expression="[^\w]|_"
noMatchError="At least one symbol char" invalid="onInvalid(event)"
property="text"/>
<mx:Script>
<![CDATA[
import mx.events.ValidationResultEvent;
private var validators:Array;
public function create():void
{
validators = [reg1, reg2, reg3, reg4];
}
private function validate():void
{
for(var i:Number = 0; i < validators.length; i++)
if(RegExpValidator(validators[i]).validate().type != ValidationResultEvent.VALID)
return;
//valid
trace(textInput.text + " is valid");
}
private function onInvalid(e:Event):void
{
var validator:RegExpValidator = e.target as RegExpValidator;
trace(validator.noMatchError);
}
]]>
</mx:Script>
</mx:Application>