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?


Or the negative equivalents?

4/15/2011 12:18:21 PM

Accepted Answer

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

12/26/2014 4:02:55 PM

I think ssg is right. It's not a really good use of Regex, especially if your software has to deal with non-US centric data entry.

For instance, if the currency symbol is the Euro, or the Japanese Yen or the British Pound any of the other dozen currency symbols out there?

What about number formatting rules?

In the US you would enter 1,000,000.00 but in France, this should be 1.000.000,00. Other countries allow spacing between digit-grouping...

If you use a straight Regex without taking the Culture into account, then you're never going to validate successfully unless you're 100% sure your software will never ever be used in a non-US centric context.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow