Search code examples
c#regexnumberscurrency

What's a C# regular expression that'll validate currency, float or integer?


What is a regular expression suitable for C# that'll validate a number if it matches the following?

 $1,000,000.150
 $10000000.199
 $10000 
 1,000,000.150
 100000.123
 10000

Or the negative equivalents?


Solution

  • You can use csmba's regex if you make one slight modification to it.

    ^\$?(\d{1,3},?(\d{3},?)*\d{3}(.\d{0,3})?|\d{1,3}(.\d{2})?)$