| 패키지 | mx.formatters |
| 클래스 | public class PhoneFormatter |
| 상속 | PhoneFormatter Formatter Object |
| 언어 버전: | ActionScript 3.0 |
| 제품 버전: | Flex 3 |
| 런타임 버전: | Flash Player 9, AIR 1.1 |
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.
MXML 구문 숨기기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="+()#-. "
/>
관련 API 요소
| 속성 | 정의 주체 | ||
|---|---|---|---|
| areaCode : Object
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 | ||
![]() | constructor : Object
지정된 객체 인스턴스의 클래스 객체 또는 생성자 함수에 대한 참조입니다. | Object | |
![]() | error : 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 | ||
| validPatternChars : String
List of valid characters that can be used
in the formatString property. | PhoneFormatter | ||
| 메서드 | 정의 주체 | ||
|---|---|---|---|
Constructor. | PhoneFormatter | ||
[재정의]
Formats the String as a phone number. | PhoneFormatter | ||
![]() |
지정된 속성이 객체에 정의되어 있는지 여부를 나타냅니다. | Object | |
![]() |
Object 클래스의 인스턴스가 매개 변수로 지정된 객체의 프로토타입 체인에 있는지 여부를 나타냅니다. | Object | |
![]() |
지정된 속성이 존재하고 열거 가능한지 여부를 나타냅니다. | Object | |
![]() |
루프 작업에서 동적 속성을 사용할 수 있는지 여부를 설정합니다. | Object | |
![]() |
로캘별 규칙에 따라 서식이 지정된 이 객체의 문자열 표현을 반환합니다. | Object | |
![]() |
지정된 객체의 문자열 표현을 반환합니다. | Object | |
![]() |
지정된 객체의 프리미티브 값을 반환합니다. | Object | |
areaCode | 속성 |
areaCode:Object| 언어 버전: | ActionScript 3.0 |
| 제품 버전: | Flex 3 |
| 런타임 버전: | Flash Player 9, AIR 1.1 |
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.
기본값: -1.
구현
public function get areaCode():Object public function set areaCode(value:Object):voidareaCodeFormat | 속성 |
areaCodeFormat:String| 언어 버전: | ActionScript 3.0 |
| 제품 버전: | Flex 3 |
| 런타임 버전: | Flash Player 9, AIR 1.1 |
Default format for the area code when the areacode
property is rendered by a seven-digit format.
기본값: "(###) ".
구현
public function get areaCodeFormat():String public function set areaCodeFormat(value:String):voidformatString | 속성 |
validPatternChars | 속성 |
validPatternChars:String| 언어 버전: | ActionScript 3.0 |
| 제품 버전: | Flex 3 |
| 런타임 버전: | Flash Player 9, AIR 1.1 |
List of valid characters that can be used
in the formatString property.
This property is used during validation
of the formatString property.
기본값: "+()#- .".
구현
public function get validPatternChars():String public function set validPatternChars(value:String):voidPhoneFormatter | () | 생성자 |
public function PhoneFormatter()| 언어 버전: | ActionScript 3.0 |
| 제품 버전: | Flex 3 |
| 런타임 버전: | Flash Player 9, AIR 1.1 |
Constructor.
format | () | 메서드 |
override public function format(value:Object):String| 언어 버전: | ActionScript 3.0 |
| 제품 버전: | Flex 3 |
| 런타임 버전: | Flash Player 9, AIR 1.1 |
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.
매개 변수
value:Object — Value to format.
|
String — Formatted String. Empty if an error occurs. A description
of the error condition is written to the error property.
|
<?xml version="1.0" encoding="utf-8"?>
<!-- Simple example to demonstrate PhoneFormatter. -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx: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 = "";
}
}
]]>
</fx:Script>
<fx:Declarations>
<mx:PhoneFormatter id="phoneFormatter"
formatString="(###) ###-####" validPatternChars="#-() "/>
<mx:PhoneNumberValidator id="pnVal" source="{phone}" property="text"
allowedFormatChars=""/>
</fx:Declarations>
<s:Panel title="PhoneFormatter Example"
width="75%" height="75%"
horizontalCenter="0" verticalCenter="0">
<mx:Form left="10" right="10" top="10" bottom="10">
<mx:FormItem label="Enter a 10-digit phone number:">
<s:TextInput id="phone" text="" width="75%"/>
</mx:FormItem>
<mx:FormItem label="Formatted phone number: ">
<s:TextInput id="formattedPhone" text="" width="75%" editable="false"/>
</mx:FormItem>
<mx:FormItem>
<s:Button label="Validate and Format" click="Format();"/>
</mx:FormItem>
</mx:Form>
</s:Panel>
</s:Application>
Tue Jun 12 2018, 03:17 PM Z
MXML 구문 표시