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>
<![CDATA[
import mx.controls.Alert;
]]>
</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>
Advertisement