tags:

views:

45

answers:

1

I am using a CompareValidator to check user input on one of my forms but for some reason it will not allow me to enter a dollar sign.

According to MSDN the currency data type in the compare validator allows:

A decimal data type that can contain currency symbols.

I am using the control below to validate:

<asp:CompareValidator ID="vld_Cash" runat="server" ControlToValidate="CashTextBox" Type="Currency" Operator="DataTypeCheck" ValidationGroup="vld_Update" ErrorMessage="The value entered for 'Cash' must be in a number format.  Do NOT include dollar signs.  Examples: 500 or 500.00" />

I also added the following to my web.config just to be sure:

<globalization culture="en-US" uiCulture="en-US"/>

But it still says any input with a $ in it is invalid. Am I missing something here?

A: 

The last comment in this thread shows why and gives you some ideas:

Currency Validator

An article dedicated to this:

ASP.Net: Validating a TextBox with a Dollar Sign (suggests using a RegularExpressionValidator).

Leniel Macaferi
True, those are some workarounds, but the MSDN docs even say "A decimal data type that can contain currency symbols." Indeed. Either the docs or the implementation is wrong. Perhaps Connect has details...
p.campbell
MSDN docs sometimes contain bugs... :) It's MSDN bug or the underlying code of the Validator that is buggy.
Leniel Macaferi
How can @p.campbell's comment appears before mine? StackOverflow bug? @Abe Miessler had commented before but deleted his comment. Maybe this caused this behavior.
Leniel Macaferi
@Leniel: I've edited my comment twice. Never saw a comment from Abe here. Everything looks in order to me. (shrug)
p.campbell
Just to clarify I haven't commented :) Until now...
Abe Miessler
Ahh... OK. Now I understand. I thought that Abe had made that first comment. @p.campbell modified his comment and I thought this was a new comment. :D
Leniel Macaferi