Currency Parsing, Regular Expressions
For example, to check if a valid monetary amount is entered in a text box named txtLoanAmount:
But for some reason it doesn’t work with a dollar sign. When the data type checked is “Currency” (in en-US culture), it works for any numeric input that includes comma and decimal formatting only. Validation fails(!?!) when the leading non-whitespace character is a dollar sign. I am not sure about other cultures. It is surprising to me, but there it is. So if you want to allow a dollar sign in your validated input, you should use a RegularExpressionValidator instead.
The regular expression given above (crafted in only a few moments) will accept an optional “$” surrounded by whitespace, at least one “leading” field of 1, 2, or 3 digits, and zero or more trailing fields with exactly three digits and optional comma separator. Finally, there is an optional decimal field with two training digits.
The strategy above will work for other cultures on a one-off basis. Unfortunately, the given regular expression will work for en-US culture only. And you can’t apply the regular expression through a Skin file. Other cultures will need different regular expressions here, and so it looks like some additional strategy would have to be developed to validate currency amounts across cultures.