Re: allow all currency symbols

Discussion in 'ASP .Net' started by Peter Blum, Oct 20, 2004.

  1. Peter Blum

    Peter Blum Guest

    Hi, please see my response to the same question that you posted here on
    www.asp.net forums:

    http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=724575

    --- Peter Blum
    www.PeterBlum.com
    Email:
    Creator of "Professional Validation And More" at
    http://www.peterblum.com/vam/home.aspx

    "magister" <> wrote in message
    news:...
    > Hello,
    >
    > Is there a way I can validate the input on a textbox for currency
    > including all currency symbols..
    >
    > At the moment I have it only for the current culture info, but most
    > banks use several different currencies...
    >
    > Thanks for any clues....
    >
    > Here's what I have so far...
    >
    >
    > try
    > {
    > Result = Double.Parse(args.Value, NumberStyles.Any);
    > done = true;
    > }
    > catch
    > {
    > done = false;
    > }
    >
    > if (done)
    > {
    > args.IsValid = true;
    > }
    > else
    > {
    > args.IsValid = false;
    > }
     
    Peter Blum, Oct 20, 2004
    #1
    1. Advertising

  2. Peter Blum

    magister Guest

    Thanks for the reply. I felt I had to share how I did this to the
    world who doesn't require client-size validation(quick search on the
    web will bring back support for currency validation with
    symbols)...This supports all currency formats installed on the
    system....

    private void Currency_ServerValidate(object source,
    System.Web.UI.WebControls.ServerValidateEventArgs args)
    {
    bool done;
    //Get the most frequent currencies
    string reg = @"(\£)|(\$)|(\€)";
    //parse win32 installed cultures for other currencies, check
    CultureTypes enum for more
    foreach(CultureInfo ci in
    CultureInfo.GetCultures(CultureTypes.InstalledWin32Cultures))
    {
    if ( reg.IndexOf(ci.NumberFormat.CurrencySymbol) == -1 )
    reg += "|("+ci.NumberFormat.CurrencySymbol+")";
    }

    Regex re = new Regex(@"("+reg+")");
    //only allow one currency mark to be replaced
    string wosymb = re.Replace(args.Value,"",1);

    //try to parse what's remaining into a decimal type, if it fails it
    ain't valid.
    try
    {
    decimal Result = decimal.Parse(wosymb,
    System.Globalization.NumberStyles.Currency);
    done = true;
    }
    catch(Exception ex)
    {
    ex = ex;
    done = false;
    }

    if (done)
    {
    args.IsValid = true;
    }
    else
    {
    args.IsValid = false;
    }
    }

    "Peter Blum" <> wrote in message news:<#>...
    > Hi, please see my response to the same question that you posted here on
    > www.asp.net forums:
    >
    > http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=724575
    >
    > --- Peter Blum
    > www.PeterBlum.com
    > Email:
    > Creator of "Professional Validation And More" at
    > http://www.peterblum.com/vam/home.aspx
    >
    > "magister" <> wrote in message
    > news:...
    > > Hello,
    > >
    > > Is there a way I can validate the input on a textbox for currency
    > > including all currency symbols..
    > >
    > > At the moment I have it only for the current culture info, but most
    > > banks use several different currencies...
    > >
    > > Thanks for any clues....
    > >
    > > Here's what I have so far...
    > >
    > >
    > > try
    > > {
    > > Result = Double.Parse(args.Value, NumberStyles.Any);
    > > done = true;
    > > }
    > > catch
    > > {
    > > done = false;
    > > }
    > >
    > > if (done)
    > > {
    > > args.IsValid = true;
    > > }
    > > else
    > > {
    > > args.IsValid = false;
    > > }
     
    magister, Nov 3, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff
    Replies:
    2
    Views:
    986
    clintonG
    Sep 19, 2006
  2. David C

    Currency Symbols

    David C, Oct 9, 2009, in forum: ASP .Net
    Replies:
    8
    Views:
    541
    Gregory A. Beamer
    Oct 12, 2009
  3. JPike

    Currency Symbols in tooltip

    JPike, Nov 11, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    134
    JPike
    Nov 15, 2004
  4. J P Singh

    Storing Currency Symbols in Database

    J P Singh, Jan 27, 2004, in forum: ASP General
    Replies:
    4
    Views:
    275
    Aaron Bertrand - MVP
    Jan 27, 2004
  5. James Sturrock

    Displaying currency symbols in select

    James Sturrock, Aug 17, 2007, in forum: Ruby
    Replies:
    6
    Views:
    172
    James Sturrock
    Aug 20, 2007
Loading...

Share This Page