Packagemx.formatters
Classpublic class PhoneFormatter
InheritancePhoneFormatter Inheritance Formatter Inheritance Object

The PhoneFormatter class formats a valid number into a phone number format, including international configurations.

A shortcut is provided for the United States seven-digit format. If the areaCode property contains a value and you use the seven-digit format string, (###-####), a seven-digit value to format automatically adds the area code to the returned String. The default format for the area code is (###). You can change this using the areaCodeFormat property. You can format the area code any way you want as long as it contains three number placeholders.

If an error occurs, an empty String is returned and a String that describes the error is saved to the error property. The error property can have one of the following values:

MXML SyntaxexpandedHide MXML Syntax

The <mx:PhoneFormatter> tag inherits all of the tag attributes of its superclass, and adds the following tag attributes:

  <mx:PhoneFormatter
    areaCode "-1"
    areaCodeFormat "(###)"
    formatString="(###) ###-####"
    validPatternChars "+()#-. "
  />
  

View the examples

See also

mx.formatters.SwitchSymbolFormatter


Public Properties
 PropertyDefined By
  areaCode : int
Area code number added to a seven-digit United States format phone number to form a 10-digit phone number.
PhoneFormatter
  areaCodeFormat : String
Default format for the area code when the areacode property is rendered by a seven-digit format.
PhoneFormatter
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
 Inheritederror : String
Description saved by the formatter when an error occurs.
Formatter
  formatString : String
String that contains mask characters that represent a specified phone number format.
PhoneFormatter
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
  validPatternChars : String
List of valid characters that can be used in the formatString property.
PhoneFormatter
Protected Properties
 PropertyDefined By
 InheriteddefaultInvalidFormatError : String = "Invalid format"
Error message for an invalid format string specified to the formatter.
Formatter
 InheriteddefaultInvalidValueError : String = "Invalid value"
Error message for an invalid value specified to the formatter.
Formatter
 InheritedpackageResources : ResourceBundle
[static] A ResourceBundle object containing all symbols from formatters.properties.
Formatter
Public Methods
 MethodDefined By
  
Constructor.
PhoneFormatter
  
Formats the String as a phone number.
PhoneFormatter
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
Property Detail
areaCodeproperty
public var areaCode:int

Area code number added to a seven-digit United States format phone number to form a 10-digit phone number. A value of -1 means do not prepend the area code.

The default value is -1.

areaCodeFormatproperty 
public var areaCodeFormat:String

Default format for the area code when the areacode property is rendered by a seven-digit format.

The default value is "(###) ".

formatStringproperty 
public var formatString:String

String that contains mask characters that represent a specified phone number format.

The default value is "(###) ###-####".

validPatternCharsproperty 
public var validPatternChars:String

List of valid characters that can be used in the formatString property. This property is used during validation of the formatString property.

The default value is "+()#- .".

Constructor Detail
PhoneFormatter()Constructor
public function PhoneFormatter()

Constructor.

Method Detail
format()method
public override function format(value:Object):String

Formats the String as a phone number. If the value cannot be formatted, return an empty String and write a description of the error to the error property.

Parameters

value:Object — Value to format.

Returns
String — Formatted String. Empty if an error occurs. A description of the error condition is written to the error property.
Examples How to use examples
PhoneFormatterExample.mxml
<?xml version="1.0" encoding="utf-8"?>
<!-- Simple example to demonstrate PhoneFormatter. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:Script>
        <![CDATA[
                
            import mx.events.ValidationResultEvent;            
            private var vResult:ValidationResultEvent;

            // Event handler to validate and format input.            
            private function Format():void
            {
                vResult = pnVal.validate();
                if (vResult.type==ValidationResultEvent.VALID) {
                    formattedPhone.text= phoneFormatter.format(phone.text);
                }
              
                else {
                    formattedPhone.text= "";
                }
            }
        ]]>
    </mx:Script>

    <mx:PhoneFormatter id="phoneFormatter" 
        formatString="(###) ###-####" validPatternChars="#-() "/>

    <mx:PhoneNumberValidator id="pnVal" source="{phone}" property="text" 
            allowedFormatChars=""/>

    <mx:Panel title="PhoneFormatter Example" width="75%" height="75%" 
            paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">

        <mx:Form>
            <mx:FormItem label="Enter a 10-digit phone number:">
                <mx:TextInput id="phone" text="" width="75%"/>
            </mx:FormItem>

            <mx:FormItem label="Formatted phone number: ">
                <mx:TextInput id="formattedPhone" text="" width="75%" editable="false"/>
            </mx:FormItem>

            <mx:FormItem>
                <mx:Button label="Validate and Format" click="Format();"/>
            </mx:FormItem>
        </mx:Form>

    </mx:Panel>
</mx:Application>




 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/livecycle/es/sdkHelp/common/langref/mx/formatters/PhoneFormatter.html