Using declared PhoneFormatter defined in mxml
<?xml version="1.0"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> [Bindable] public var rawPhone:String = "1234567"; public function formatThis(plainText:String):String { if(plainText.length == 7) fmtPhone.formatString = "###-####"; else fmtPhone.formatString = "###-###-####"; return(fmtPhone.format(plainText)); } </mx:Script> <mx:PhoneFormatter id="fmtPhone" /> <mx:Label text="{formatThis(rawPhone)}" /> </mx:Application>