Share on Google+Share on Google+

ZipCodeFormatter in Flex4

Ads
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

Advertisements

Ads

Posted on: June 3, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.

Advertisement