Home Tutorial Flex Flex4 Components ZipCodeFormatter in Flex4

 
 

Share on Google+Share on Google+
ZipCodeFormatter in Flex4
Posted on: June 3, 2010 at 12:00 AM
Advertisement
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"/>

</mx:FormItem>

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

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

</mx:FormItem>

<mx:FormItem>

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

</mx:FormItem>

</mx:Form>

</s:Panel>

</s:Application>

Output:

Running Application:

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

Download this code

Advertisement

Related Tags for ZipCodeFormatter in Flex4:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 3, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com