| 包 | mx.formatters | 
| 类 | public class ZipCodeFormatter | 
| 继承 | ZipCodeFormatter    Formatter   Object | 
| 语言版本: | ActionScript 3.0 | 
| 产品版本: | Flex 3 | 
| 运行时版本: | Flash Player 9, AIR 1.1 | 
formatString 属性将有效数字设置为下列格式之一。
  
  - #####-####
 - ##### ####
 - #####
 - ### ###(加拿大)
 
必须为六位数字的号码提供一个六位数字的掩码。如果您使用五位数字或九位数字的掩码,则可以设置五位数字或九位数字号码的格式。
如果出现错误,则会返回一个空 String,以及一个说明已将此错误保存到 error 属性的 String。error 属性可以是下列值之一:
- 
                     
"Invalid value"表示传递给format()方法的数值无效。此值应该是 Number 或 String 形式的有效数字(适用于字母数字值,加拿大邮政编码除外),或者数字位数不符合formatString属性中允许的位数。 -  
                     
"Invalid format"表示formatString属性中的字符总数不符合validFormatChars属性中指定的允许字符数,或者数字占位符数目不等于 9、5 或 6。 
隐藏 MXML 语法The <mx:ZipCodeFormatter> tag
  inherits all of the tag attributes of its superclass,
  and adds the following tag attributes:
  <mx:ZipCodeFormatter
    formatString="#####|#####-####|### ###"
  />
  
  
  相关 API 元素
公共属性
| 属性 | 由以下参数定义 | ||
|---|---|---|---|
![]()  | constructor : Object 
	 对类对象或给定对象实例的构造函数的引用。  | Object | |
![]()  | error : String 
	  发生错误时由 formatter 保存的说明。  | Formatter | |
| formatString : String 
	  掩码模式。  | ZipCodeFormatter | ||
受保护的属性
公共方法 
| 方法 | 由以下参数定义 | ||
|---|---|---|---|
	  构造函数。  | ZipCodeFormatter | ||
[覆盖] 
	  使用指定的格式设置 String 的格式。  | ZipCodeFormatter | ||
![]()  | 
	 表示对象是否已经定义了指定的属性。  | Object | |
![]()  | 
	 表示 Object 类的实例是否在指定为参数的对象的原型链中。  | Object | |
![]()  | 
	 表示指定的属性是否存在、是否可枚举。  | Object | |
![]()  | 
     设置循环操作动态属性的可用性。  | Object | |
![]()  | 
	 返回此对象的字符串表示形式,其格式设置遵守区域设置特定的约定。  | Object | |
![]()  | 
	 返回指定对象的字符串表示形式。  | Object | |
![]()  | 
	 返回指定对象的原始值。  | Object | |
受保护的方法 
属性详细信息
formatString | 属性 | 
构造函数详细信息
ZipCodeFormatter | () | 构造函数 | 
public function ZipCodeFormatter()| 语言版本: | ActionScript 3.0 | 
| 产品版本: | Flex 3 | 
| 运行时版本: | Flash Player 9, AIR 1.1 | 
构造函数。
方法详细信息
format | () | 方法 | 
示例 如何使用本示例 
ZipCodeFormatterExample.mxml
<?xml version="1.0" encoding="utf-8"?>
<!-- Simple example to demonstrate ZipCodeFormatter. -->
<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 = zcVal.validate();
                if (vResult.type == ValidationResultEvent.VALID) {
                    formattedZipcode.text = zipFormatter.format(zip.text);
                } else {
                    formattedZipcode.text = "";
                }
            }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <mx:ZipCodeFormatter id="zipFormatter" formatString="#####-####"/>
        <mx:ZipCodeValidator id="zcVal" source="{zip}" property="text" allowedFormatChars=""/>
    </fx:Declarations>
    <s:Panel title="ZipCodeFormatter Example"
            width="75%" height="75%" 
            horizontalCenter="0" verticalCenter="0">
        <mx:Form left="10" right="10" top="10" bottom="10">
            <mx:FormItem label="Enter a 5 or 9 digit U.S. ZIP code:" width="100%">
                <s:TextInput id="zip" text=""/>
            </mx:FormItem>
            <mx:FormItem label="Formatted ZIP code: " width="100%">
                <s:TextInput id="formattedZipcode" text="" 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, 11:04 AM Z
 
显示 MXML 语法