mx.formatters
ZipCodeFormatter クラス
ZipCodeFormatter クラス
mx.formatters.Formatter の拡張ZipCodeFormatter クラスは、ユーザーが定義した formatString プロパティの設定に基づいて、有効な数値を次のいずれかの形式にフォーマットします。
- #####-####
- ##### ####
- #####
- ### ### (カナダ式)
6 桁のマスクには 6 桁の数値を設定する必要があります。5 桁または 9 桁のマスクを使用している場合は、5 桁または 9 桁の数値を使用してフォーマットできます。
MXML シンタックス
<mx:ZipCodeFormatter> タグには、次のプロパティを使用できます。
<mx:ZipCodeFormatter
formatString="#####|#####-####|### ###"
/>
例を参照するにはここをクリックしてください
関連項目
SwitchSymbolFormatter
| format( value)
: String
指定のフォーマットを使用して、ストリングをフォーマットします。 |
format
format( value)
: String
指定のフォーマットを使用して、ストリングをフォーマットします。値をフォーマットできない場合は、空のストリングが返され、error プロパティにはエラーの説明が格納されます。
パラメータ
value - フォーマットする値を表します。
戻り値
フォーマットしたストリング。エラーが発生した場合は空です。
formatString
formatString:String
ユーザー定義のマスクパターンを表します。デフォルト値は "#####" です。有効な値は、"#####-####"、"##### ####"、"#####"、"###-###"、および "### ###" です。
| ZipCodeFormatterExample.mxml |
<?xml version="1.0" encoding="utf-8"?>
<!-- ZipCode formatter の使用方法を示す簡単な例 -->
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" backgroundColor="#FFFFFF">
<mx:Script>
<![CDATA[
function Format()
{
if(mx.validators.Validator.isValid(this,'CheckModel.Zip'))
formattedzipcode.text= zipformatter.format(zip.text);
else
formattedzipcode.text= "";
}
]]>
</mx:Script>
<mx:Panel title="Validate and Format Panel" backgroundColor="#0C8BF3">
<mx:Model id="CheckModel">
<Zip>{zip.text}</Zip>
</mx:Model>
<mx:Label text="Enter below 9 digit Zip code to be validated and formatted:"color="#FFFFFF"/>
<mx:TextInput id="zip" text="Enter zip code here" />
<mx:Button label="Validate and Format" click="Format();" width="160"/>
<mx:TextInput id="formattedzipcode" editable="false" color="#0000FF"/>
</mx:Panel>
<!-- Result of zipcode validation is formatted using ZipCodeFormatter and displayed. -->
<mx:ZipCodeFormatter id="zipformatter" formatString="#####-####"/>
<!-- ZipCodeValidator validates user input. -->
<mx:ZipCodeValidator field="CheckModel.Zip" wrongLengthError="Invalid Format, please enter 9 digit zip code."
allowedFormatChars="#" domain="US Only"/>
</mx:Application>
|