Here's what I use:

var myNumericString:String = RegExUtil.strip(myInputBox.text,
RegExUtil.NON_NUMERIC_CHARACTERS);

package
{
      public class RegExUtil
      {
           public static var NON_NUMERIC_CHARACTERS : String = "[^0-9]+";



           public static function strip(source:String,
pattern:String):String
           {
                if (source.length && pattern.length)
               {
                     var regex:RegExp = new RegExp(pattern,"g");
                     source = source.replace(regex,"");
               }
               return source;
          }
     }
}

-TH

--- In [email protected], "Josh McDonald" <[EMAIL PROTECTED]> wrote:
>
> The cleanupNumberInput() function could be better, but it's a starting
point
> :)
>
> http://pastie.textmate.org/329356
>
> -Josh
>
> On Wed, Dec 3, 2008 at 10:23 AM, Tracy Spratt [EMAIL PROTECTED] wrote:
>
> > You could use "restrict" to prevent entry of any non-numeric
characters.
> >
> > Tracy
> >
> >
> > ------------------------------
> >
> > *From:* [email protected]
[mailto:[EMAIL PROTECTED] *On
> > Behalf Of *flexcoder2008
> > *Sent:* Tuesday, December 02, 2008 6:51 PM
> > *To:* [email protected]
> > *Subject:* [flexcoders] Unformatting currency values - best
practice?
> >
> >
> >
> > What is the best practice or a good recommendation for formatting
> > currency values and then removing the currency formatting for saving
> > to the database?
> >
> > Here's what I have attempted to do so far. It works - but only if
the
> > user enters plain old numbers - if they add any currency symbol or
> > thousand separator, it fails.
> >
> > I have a form which has some textInput's that are formatted with
> > currencyFormatters. I initialize each textInput's .data property to
> > "0". The textInput displays formatted currency amounts from xml data
> > retrieved from the database. On the focusIn event, the text property
> > is assigned to the textInput's .data property, so the value stays
the
> > same but the formatting is gone. And when a change event fires, the
> > unformatted text in the textInput gets updated to the data property
as
> > well.
> >
> > On the FocusOut event, the currency formatting is re-applied.
> >
> > When I save to the db, I use the textInput's .data property. So for
> > the most part this works, but fails if the user enters any currency
> > symbols.
> >
> > Is there a good class or function someone could recommend to take a
> > currency value in a textInput and strip out all the extra formatting
> > characters? I am also trying to implement localization, so the
> > various currency symbols will be different depending on the locale.
> >
> > Thanks
> >
> >
> >
>
>
>
> --
> "Therefore, send not to know For whom the bell tolls. It tolls for
thee."
>
> Like the cut of my jib? Check out my Flex blog!
>
> :: Josh 'G-Funk' McDonald
> :: 0437 221 380 :: [EMAIL PROTECTED]
> :: http://flex.joshmcdonald.info/
> :: http://twitter.com/sophistifunk
>


Reply via email to