Validating real/integer numbers in Flex

Written for: Flex

Below is a short code to determine whether a number is real (floating). To find if a number is an integer, change the domain property in NumberValidator tag from “real” to “int”.


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
    layout="vertical">

    <mx:Script>
        <!&#91;CDATA&#91;
            import mx.controls.Alert;
        &#93;&#93;>
    </mx:Script>

    <mx:TextInput id="myTxtInput"/> 

    <mx:NumberValidator id="myNumberValidator"
        domain="real"
        source="{myTxtInput}"
        property="text"
        trigger="{myTxtInput}"
        triggerEvent="focusOut"
        valid="Alert.show('real number')"
        invalid="Alert.show('hmmm....unreal number?')"/>

</mx:Application>

Advertisements
Tagged , , ,

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

Advertisements