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:
"Invalid value"means an invalid numeric value is passed to theformat()method. The value should be a valid number in the form of a Number or a String, or the value contains a different number of digits than what is specified in the format String."Invalid format"means any of the characters in theformatStringproperty do not match the allowed characters specified in thevalidPatternCharsproperty, or theareaCodeFormatproperty is specified but does not contain exactly three numeric placeholders.
See also:
Constructor
Variables
areaCode:Dynamic
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.
areaCodeFormat:String
Default format for the area code when the areacode
property is rendered by a seven-digit format.
formatString:String
String that contains mask characters that represent a specified phone number format.
validPatternChars:String
List of valid characters that can be used
in the formatString property.
This property is used during validation
of the formatString property.
Methods
format(value:Dynamic):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 | Value to format. |
|---|
Returns:
Formatted String. Empty if an error occurs. A description
of the error condition is written to the error property.