Mega Code Archive

 
Categories / Flex / Data Model
 

Use error property to check if a problem occurred during formatting

<?xml version="1.0"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">     <mx:Script>                  import mx.formatters.*;         public function formatThis(plainText:String):String         {             var fmtPhone:PhoneFormatter = new PhoneFormatter();             var formattedString:String = fmtPhone.format(plainText);                          if(fmtPhone.error == "Invalid value")             {                              mx.controls.Alert.show('invalid.');                          }else if(fmtPhone.error == "Invalid format"){                              mx.controls.Alert.show('invalid.');                          }             return(formattedString);         }            </mx:Script>     <mx:Label text="{formatThis('222')}" /> </mx:Application>