<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
[Bindable]
public var results:String="";
public function formatNow():void {
phoneFormatter.format(phone.text);
if(phoneFormatter.error == "Invalid value"){
results=phoneFormatter.error+" - "+ phone.text;
} else {
results=phoneFormatter.format(phone.text);
phone.text=phoneFormatter.format(phone.text);
}
}
</mx:Script>
<mx:PhoneFormatter id="phoneFormatter" formatString="(###) ###-####" validPatternChars="#-() "/>
<mx:Panel title="Formatter Error Example" width="300" height="300">
<mx:HBox>
<mx:Label text="Phone number:" />
<mx:TextInput id="phone" width="75%" change="formatNow()" restrict="0-9()-."/>
<mx:TextArea id="formatterResults" htmlText="{results}" width="100%" height="100%" editable="false"/>
</mx:HBox>
</mx:Panel>
</mx:Application>
|