An culture-friendly money matching expression : Culture Format « I18N Internationalization « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
using System.Reflection;

public class MainClass{

   public static void Main(){
        string[] money = new string[] { "$0.99", "$0,99", "$1000000.00", "$10.25", "$90,000.00", "$90.000,00", "$1,000,000.00", "$1,000000.00" };
        NumberFormatInfo info = CultureInfo.CurrentCulture.NumberFormat;
        Regex moneyint = new Regex(String.Format(@"\{0}(\d{{1,3}}\{0})*\d+\{1}\d{{2}}",
            info.CurrencyGroupSeparator, info.CurrencyDecimalSeparator));

        foreach (string m in money)
        {
            Console.WriteLine("{0}: {1}", m, moneyint.IsMatch(m));
        }
   }
}
$0.99: False
$0,99: False
$1000000.00: False
$10.25: False
$90,000.00: True
$90.000,00: False
$1,000,000.00: True
$1,000000.00: True








21.6.Culture Format
21.6.1.Use current culture to format currency
21.6.2.Implement Format for different Culture Information
21.6.3.Get datetime formatting info from a CultureInfo
21.6.4.Get numeric formatting info from a CultureInfo
21.6.5.Save CultureInfo, its DateTimeFormatInfo and NumberFormatInfo to a text file
21.6.6.Culture formatting: en-US
21.6.7.Culture formatting: en-GB
21.6.8.An culture-friendly money matching expression
21.6.9.Culture-specific formatting: en-US, en-GB, ja, ar
21.6.10.Culture information: DisplayName, NativeName and LCID
21.6.11.Culture information: primary Calendar and optional Calendar
21.6.12.Culture information: Days
21.6.13.Culture information: Months
21.6.14.Culture information: Long Date Format and Short Date Format
21.6.15.Culture information: Currency Format
21.6.16.Culture information: Number Format
21.6.17.Culture information: Number Group Separator