Use NumberValidator to validate and CurrencyFormatter to format
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" minWidth="1024" minHeight="768">
<mx:CurrencyFormatter id="currencyFormatter" currencySymbol="L" thousandsSeparatorFrom="." decimalSeparatorFrom=","/>
<mx:NumberValidator id="numValidator" property="text"/>
<mx:Script>
import mx.events.ValidationResultEvent;
private var vResult:ValidationResultEvent;
private function currencyFormat():void {
vResult = numValidator.validate(inputCurrency.text);
if (vResult.type==ValidationResultEvent.VALID) {
inputCurrency.text =
currencyFormatter.format(inputCurrency.text);
} else {
inputCurrency.text= "";
}
}
</mx:Script>
<mx:Label text="Currency Input"/>
<mx:TextInput id="inputCurrency" focusOut="currencyFormat()" width="300"/>
</mx:Application>
Related examples in the same category