Flex Validating required fields

Category: flex tutorials    |    1,364 views

The Validator class, the base class for all Flex validators, contains a required property that when set to true causes validation to fail when a field is empty. You use this property to configure the validator to fail when a user does not enter data in a required input field.

You typically call the validate() method to invoke a validator on a required field. This is often necessary because you cannot guarantee that an event occurs to trigger the validation– an empty input field often means that the user never gave the input control focus.

The following example performs a validation on a required input field:

<mx:TextInput id="inputA"/><?xml version=”1.0″?>

<!– validators\RequiredVal.mxml –>

<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”>
<mx:StringValidator id=”reqV”

source=”{inputA}”

property=”text”

required=”true”/>

<mx:Button label=”Submit”

click=”reqV.validate();”/>

</mx:Application>

Share/Save/Bookmark

1 Star2 Stars (+6)

Tags: ,

0 responses so far!

Leave a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word