ZipCodeFormatter in Flex4


 

ZipCodeFormatter in Flex4

The ZipCodeFormatter class is used for format a zip code. You can use formatString property for formatting a zip code.

The ZipCodeFormatter class is used for format a zip code. You can use formatString property for formatting a zip code.

ZipCodeFormatter in Flex4:

The ZipCodeFormatter class is used for format a zip code. You can use formatString property for formatting a zip code.
There are many format for zip code such as
#####-####
##### ####
#####
### ###
If an error occurs this error will be shown by the error property. The error property has two types of error values: Invalid value, Invalid format.
The tag of ZipCodeFormatter is <mx:ZipCodeFormatter>.

Example:

<?xml version="1.0" encoding="utf-8"?>

<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"

minWidth="955" minHeight="600">

<fx:Script>

<![CDATA[

import mx.events.ValidationResultEvent;

private var result:ValidationResultEvent;

private function Format():void

{

result = zcValidator.validate();

if (result.type==ValidationResultEvent.VALID) {

Zipcodelbl.text= zipFormatter.format(ziptxt.text);

}

else {

Zipcodelbl.text= "Invalid ZipCode";

}

}

]]>

</fx:Script>

<fx:Declarations>

<mx:ZipCodeFormatter id="zipFormatter" formatString="#####-####"/>

<mx:ZipCodeValidator id="zcValidator" source="{ziptxt}" property="text"/>

</fx:Declarations>

<s:Panel title="ZipCodeFormatter Example" width="565">

<mx:Form backgroundColor="#096465" width="563">

<mx:FormItem label="Enter a ZIP code:" color="#FFFFFF" fontFamily="verdana">

<s:TextInput id="ziptxt" color="#000000" fontFamily="verdana"/>

0

</mx:FormItem>

<mx:FormItem label="Formatted ZIP code: " color="#FFFFFF" fontFamily="verdana">

<s:Label id="Zipcodelbl" color="#FFFFFF" fontFamily="verdana"/>

1

</mx:FormItem>

<mx:FormItem>

<s:Button label="Format" click="Format();"/>

2

</mx:FormItem>

</mx:Form>

</s:Panel>

3

</s:Application>

Output:

Running Application:

To view this page ensure that Adobe Flash Player version 10.0.0 or greater is installed.

4

Download this code

Ads