<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flex Examples &#187; currencySymbol</title>
	<atom:link href="http://blog.flexexamples.com/tag/currencysymbol/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexexamples.com</link>
	<description>Just a bunch of Adobe Flex Examples</description>
	<lastBuildDate>Wed, 26 Jan 2011 18:09:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using the CurrencyValidator and CurrencyFormatter classes to validate and format numbers</title>
		<link>http://blog.flexexamples.com/2007/08/25/using-the-currencyvalidator-and-currencyformatter-classes-to-validate-and-format-numbers/</link>
		<comments>http://blog.flexexamples.com/2007/08/25/using-the-currencyvalidator-and-currencyformatter-classes-to-validate-and-format-numbers/#comments</comments>
		<pubDate>Sun, 26 Aug 2007 03:37:59 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[CurrencyFormatter]]></category>
		<category><![CDATA[CurrencyValidator]]></category>
		<category><![CDATA[currencySymbol]]></category>
		<category><![CDATA[validate()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/25/using-the-currencyvalidator-and-currencyformatter-classes-to-validate-and-format-numbers/</guid>
		<description><![CDATA[<p>The following entry shows how users can store an unformatted number and display it back to users when the TextInput control is being edited. When the text input control loses focus, the data is validated and formatted (if the data was valid) or focus is returned to the control if validation failed.</p> <p>Full code after [...]]]></description>
			<content:encoded><![CDATA[<p>The following entry shows how users can store an unformatted number and display it back to users when the TextInput control is being edited. When the text input control loses focus, the data is validated and formatted (if the data was valid) or focus is returned to the control if validation failed.</p>
<p>Full code after the jump.</p>
<p><span id="more-130"></span></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/08/25/using-the-currencyvalidator-and-currencyformatter-classes-to-validate-and-format-numbers/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            [Bindable]
            [Embed(source="assets/bulletCheck.png")]
            public var BulletCheck:Class;

            [Bindable]
            [Embed(source="assets/bulletCritical.png")]
            public var BulletCritical:Class;
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.controls.TextInput;
            import mx.events.ValidationResultEvent;

            private function formatString(evt:FocusEvent):void {
                var ti:TextInput = TextInput(evt.currentTarget);
                if (validateCurrency()) {
                    ti.data = ti.text;
                    ti.text = currencyFormatter.format(ti.data);
                } else {
                    ti.setFocus();
                }
            }

            private function unformatString(evt:FocusEvent):void {
                var ti:TextInput = TextInput(evt.currentTarget);
                ti.text = String(ti.data);
            }

            private function validateCurrency():Boolean {
                var isValid:Boolean = false;
                var result:ValidationResultEvent = currencyValidator.validate();
                switch (result.type) {
                    case ValidationResultEvent.VALID:
                        isValid = true;
                        image.source = BulletCheck;
                        break;
                    case ValidationResultEvent.INVALID:
                        currencyValidator.source.setFocus();
                        image.source = BulletCritical;
                        break;
                }
                return isValid;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:CurrencyFormatter id="currencyFormatter"
            currencySymbol="$"
            useThousandsSeparator="true"
            precision="2" /&gt;

    &lt;mx:CurrencyValidator id="currencyValidator"
            currencySymbol="$"
            source="{textInput}"
            property="text" /&gt;

    &lt;mx:Form&gt;
        &lt;mx:FormHeading label="Enter base price" /&gt;
        &lt;mx:FormItem label="Price:" direction="horizontal" required="true"&gt;
            &lt;mx:TextInput id="textInput"
                    data=""
                    focusIn="unformatString(event)"
                    focusOut="formatString(event)" /&gt;
            &lt;mx:Image id="image" verticalAlign="bottom" width="20"  /&gt;
        &lt;/mx:FormItem&gt;
        &lt;mx:FormItem&gt;
            &lt;mx:Button id="button"
                    label="Validate"
                    click="validateCurrency()" /&gt;
        &lt;/mx:FormItem&gt;
    &lt;/mx:Form&gt;

&lt;/mx:Application&gt;
</pre>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Using the CurrencyValidator and CurrencyFormatter classes to validate and format numbers on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/08/25/using-the-currencyvalidator-and-currencyformatter-classes-to-validate-and-format-numbers/',contentID: 'post-130',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'currencySymbol,validate()',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/08/25/using-the-currencyvalidator-and-currencyformatter-classes-to-validate-and-format-numbers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

