Use error property to check if a problem occurred during formatting : PhoneFormatter « Data Model « Flex






Use error property to check if a problem occurred during formatting

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>

   
    
    
    
    
    
    
    
    
  








Related examples in the same category

1.Using declared PhoneFormatter defined in mxmlUsing declared PhoneFormatter defined in mxml
2.PhoneFormatter for formatting unformatted phone digitsPhoneFormatter for formatting unformatted phone digits
3.Using ActionScript to format based on data lengthUsing ActionScript to format based on data length
4.Create an instance of a PhoneFormatter using ActionScriptCreate an instance of a PhoneFormatter using ActionScript
5.Set format string for PhoneFormatterSet format string for PhoneFormatter
6.Set validPatternChars for PhoneFormatterSet validPatternChars for PhoneFormatter
7.Add area code for PhoneFormatterAdd area code for PhoneFormatter
8.Set area code format for PhoneFormatterSet area code format for PhoneFormatter
9.Using the PhoneFormatter classUsing the PhoneFormatter class
10.PhoneFormatter and formatting parametersPhoneFormatter and formatting parameters