Using StringValidators in Flex.

packages to import:

import mx.events.ValidationResultEvent;
import mx.validators.Validator;
import mx.validators.StringValidator;

mxml Tag to use:

<mx:StringValidator id=”strVal” property=”text” />

on what control:

<mx:TextInput x=”256″ y=”10″ id=”txtuname” width=”206″ tabIndex=”1″/> 

ActionScript code to use:

strVal.source=txtuname;
strVal.required=true;
strVal.requiredFieldError=”Enter Your User Name”;
var bill_result1:ValidationResultEvent=strVal.validate();
if(bill_result1.type==ValidationResultEvent.INVALID)
{
txtuname.setFocus();
Alert.show(bill_result1.message,this.title);
}

Hope you understand the code.Enjoy the code.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: