I have an ASP.NET Core 2 project in which I use annotations to validate a currency field, like this:
public class Record {
public const string CurrencyRegex = @"^[$]?\d+[,.]?\d?\d? ?[€$]?$";
[RegularExpression(Record.CurrencyRegex, ErrorMessage = "Invalid currency format")]
public string Budget { get; set; }
The problem is the decimal separator ([,.]?\d?\d?
) is not perfect. I need the expression be sensible of the current context culture. If is UK/US, the decimal separator should be validated as .
, but id there, say FR culture, the decimal should be considered as ,
How can I use a "context-dependent constant" as RegularExpression
attribute value, if possible?