allow all currency symbols

  • Thread starter Thread starter magister
  • Start date Start date
M

magister

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;
}
 
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;
}
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top