Matching money : Regex Money : Regular Expression C# Examples


C# Examples » Regular Expression » Regex Money »

 

Matching money









    
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(){
                Regex  moneyR  =  new  Regex(@"\$(((\d{1,3},)+\d{3})|\d+)\.\d{2}");
                string[]  money  =  new  string[]  {  "$0.99",  
                                                                                "$1099999.00",  
                                                                                "$10.25",  
                                                                                "$90,999.99",  
                                                                                "$1,990,999.99",  
                                                                                "$1,999999.99"  };
                foreach  (string  m  in  money){
                        Console.WriteLine(m);
                        Console.WriteLine(moneyR.IsMatch(m));
                }
      }
}
    
   
  
   



Output

$0.99
True
$1099999.00
True
$10.25
True
$90,999.99
True
$1,990,999.99
True
$1,999999.99
False


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Regular Expression
» Regex Money