| パッケージ | mx.formatters |
| クラス | public class PhoneFormatter |
| 継承 | PhoneFormatter Formatter Object |
| 言語バージョン: | ActionScript 3.0 |
| 製品バージョン: | Flex 3 |
| ランタイムバージョン: | Flash Player 9, AIR 1.1 |
7 桁の米国形式の電話番号については、ショートカットが用意されています。 areaCode プロパティに値が含まれ、7 桁の形式のストリング(###-####)を使用した場合、返されるストリングに自動的に市外局番が追加されます。 市外局番のデフォルトの形式は、(###)です。 この形式は areaCodeFormat プロパティを使用して変更できます。 エリアコードは、3 桁のプレースホルダーーを使用する限り任意に設定できます。
エラーが発生すると、空のストリングが返され、エラーを説明するストリングが error プロパティに保存されます。 この error プロパティに保存される可能性のある値は、次のうちのいずれかです。
-
"Invalid value"は、無効な数値がformat()メソッドに渡されたことを示します。 値は Number 型または String 型の有効な数値にする必要があります。または、値の桁数が、フォーマットストリングで指定された桁数と異なっています。 -
"Invalid format"は、formatStringプロパティの任意の文字がvalidPatternCharsプロパティで指定されている文字と一致しない、またはareaCodeFormatプロパティが指定されているのに対して、数値プレースホルダーーの数が 3 ではないことを示します。
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
10 桁の電話番号を構成するために米国形式の 7 桁の電話番号に追加される市外局番(エリアコード)を表します。 | PhoneFormatter | ||
| areaCodeFormat : String
areacode プロパティが 7 桁形式で表示された場合に使用される、市外局番のデフォルトの形式です。 | PhoneFormatter | ||
![]() | constructor : Object
指定されたオブジェクトインスタンスのクラスオブジェクトまたはコンストラクター関数への参照です。 | Object | |
![]() | error : String
エラーが発生したときにフォーマッターによって保存される説明を表します。 | Formatter | |
| formatString : String
指定の電話番号のフォーマットを示すマスク文字を含むストリングを表します。 | PhoneFormatter | ||
| validPatternChars : String
formatString プロパティで使用できる有効な文字のリストを表します。 | PhoneFormatter | ||
プロテクトプロパティ
パブリックメソッド
| メソッド | 定義元 | ||
|---|---|---|---|
コンストラクターです。 | PhoneFormatter | ||
[オーバーライド]
ストリングを電話番号としてフォーマットします。 | PhoneFormatter | ||
![]() |
オブジェクトに指定されたプロパティが定義されているかどうかを示します。 | Object | |
![]() |
Object クラスのインスタンスが、パラメーターとして指定されたオブジェクトのプロトタイプチェーン内にあるかどうかを示します。 | Object | |
![]() |
指定されたプロパティが存在し、列挙できるかどうかを示します。 | Object | |
![]() |
ループ処理に対するダイナミックプロパティの可用性を設定します。 | Object | |
![]() |
ロケール固有の規則に従って書式設定された、このオブジェクトのストリング表現を返します。 | Object | |
![]() |
指定されたオブジェクトのストリング表現を返します。 | Object | |
![]() |
指定されたオブジェクトのプリミティブな値を返します。 | Object | |
プロテクトメソッド
プロパティの詳細
areaCode | プロパティ |
areaCodeFormat | プロパティ |
formatString | プロパティ |
validPatternChars | プロパティ |
validPatternChars:String| 言語バージョン: | ActionScript 3.0 |
| 製品バージョン: | Flex 3 |
| ランタイムバージョン: | Flash Player 9, AIR 1.1 |
formatString プロパティで使用できる有効な文字のリストを表します。 このプロパティは、formatString プロパティの検証に使用されます。
デフォルト値: "+()#- ."。
実装
public function get validPatternChars():String public function set validPatternChars(value:String):voidコンストラクターの詳細
PhoneFormatter | () | コンストラクター |
public function PhoneFormatter()| 言語バージョン: | ActionScript 3.0 |
| 製品バージョン: | Flex 3 |
| ランタイムバージョン: | Flash Player 9, AIR 1.1 |
コンストラクターです。
メソッドの詳細
format | () | メソッド |
override public function format(value:Object):String| 言語バージョン: | ActionScript 3.0 |
| 製品バージョン: | Flex 3 |
| ランタイムバージョン: | Flash Player 9, AIR 1.1 |
ストリングを電話番号としてフォーマットします。 値をフォーマットできない場合、空のストリングが返され、error プロパティにエラーの説明が書き込まれます。
パラメーター
value:Object — フォーマットする値を表します。
|
String — フォーマットしたストリングを表します。 エラーが発生した場合は空です。 エラーの状態を示す説明が error プロパティに書き込まれます。
|
例 この例の使用方法
PhoneFormatterExample.mxml
<?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, 10:34 AM Z
MXML シンタックスを表示