I do not think you need any regex if you just need to validate price numbers in C#.
I'd suggest using Decimal
type, here you can find why. The Decimal
class contains a static TryParse
method that can be used to validate numbers as valid decimal
numbers. Here is a slightly modified example from MSDN (I decided to go with InvariantCulture
, but it depends on whether your DB contains currencies in EN-US format or not):
var validated = false;
decimal number;
// Parse currency value using current culture.
var value = "1,097.63";
var style = System.Globalization.NumberStyles.Number;
var culture = System.Globalization.CultureInfo.InvariantCulture;
if (!Decimal.TryParse(value, style, culture, out number))
if (number > 0) // Check if the value is not negative or zero
validated = true;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…