An culture-friendly money matching expression : Culture Format : I18N Internationalization C# Examples


C# Examples » I18N Internationalization » Culture Format »

 

An culture-friendly money matching expression









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



Output

$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


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo I18N Internationalization
» Culture Format