Home Tutorial Flex Flex4 Components PhoneFormatter in Flex4

 
 

Share on Google+Share on Google+
PhoneFormatter in Flex4
Posted on: June 2, 2010 at 12:00 AM
Advertisement
The PhoneFormatter class changes a number into a phone number format.

PhoneFormatter in Flex4:

The PhoneFormatter class changes a number into a phone number format.
You can use the formatString property for formatted a number.  The default area code is (###). You can set the areaCodeFormat property for area code.
If an error occurs this error is saved to the error property. The error property has two types of error values: Invalid value, Invalid format. The tag of NumberFormatter is <mx:NumberFormatter>. You will be declare a formatter in <fx:Declarations> tag.

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 = pnValidator.validate();

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

phonelbl.text= phoneFormatter.format(phonetxt.text);

}

else {

phonelbl.text= "Invalid Phone No.";

}

}

]]>

</fx:Script>

<fx:Declarations>

<mx:PhoneFormatter id="phoneFormatter" formatString="(###) ###-####"

 validPatternChars="#-() "/>

<mx:PhoneNumberValidator id="pnValidator" source="{phonetxt}" property="text"/>

</fx:Declarations>

<s:Panel title="PhoneFormatter Example" width="612">

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

<mx:FormItem label="Enter phone no.:" color="#FFFFFF" fontFamily="verdana">

<s:TextInput id="phonetxt" width="100%" color="#000000" fontFamily="verdana"/>

</mx:FormItem>

<mx:FormItem label="Formatted phone no.: " color="#FFFFFF" fontFamily="verdana">

<s:Label id="phonelbl" 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 PhoneFormatter 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 2, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com