Search

CompareValidator does not allow Currency to have the $ symbol in it. by Abe Miessler1

Active

1
0
Sign in
to vote
Type: Bug
ID: 595932
Opened: 9/7/2010 4:40:40 PM
Access Restriction: Public
2
Workaround(s)
0
User(s) can reproduce this bug
According to MSDN the Currency data type is:
"A decimal data type that can contain currency symbols. "

But if you do a DataTypeCheck on a value that has a dollar sign in it the page will not validate.

There seem to be a few posts out on the internet about this problem:
http://graciesdad.wordpress.com/2009/08/26/asp-net-validating-a-text-box-with-a-dollar-sign/
http://forums.asp.net/t/1212378.aspx
http://stackoverflow.com/questions/3663190/why-cant-i-validate-values-with-the-symbol-in-it
Details (expand)

Visual Studio/Silverlight/Tooling version

Visual Studio 2010

What category (if any) best represents this feedback?

 

Steps to reproduce

Add a text box:

<asp:TextBox id="cashTextBox" runat="server />

Add a compare validator:

<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" />

Add the following line to the system.web section of your config:

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

Enter a value with a $ symbol in it into the CashTextBox TextBox.

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

Page is invalid

Expected results

Page is valid
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 11/29/2010 at 3:48 PM
I have notified the documentation team of the error in the documentation and they will correct the documentation. Thanks!
Posted by Abe Miessler1 on 11/2/2010 at 2:23 PM
Is there anything going on with this?
Posted by Abe Miessler1 on 10/4/2010 at 5:02 PM
I know what a regular expression is. I included a regular expression validator (including the regex) in my work around. If this is how this control is intended to work then why does your documentation say the Currency data type is:
"A decimal data type that can contain currency symbols. "

Your suggestion that I use the Regex Validator seems like an attempt to side step my question. My point is that YOUR documentation says the Currency Data type can include the currency symbol, so how can this be working as it intended? Is there anyway for me to reopen this because I don't think it should have been closed.
Posted by Microsoft on 10/4/2010 at 1:05 PM
Hi Abe,

The CompareValidator uses a regular expression to perform validation. This regular expression is not localized. If you want to validate currency amounts, and you don't need to localize for multiple countries, then I recommend that you use a RegularExpressionValidator. Try this website for some currency regular expressions: http://regexlib.com/
Posted by Microsoft on 9/7/2010 at 8:06 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 9/7/2010 at 5:03 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by Abe Miessler1 on 9/7/2010 at 4:43 PM
Use a regularExpressionValidator instead:

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="CashTextBox"
ErrorMessage="Currency Format Only Accepted For Price" ValidationExpression="(?n:(^\$?(?!0,?\d)\d{1,3}(?=(?<1>,)|(?<1>))(\k<1>\d{3})*(\.\d\d)?)$)"></asp:RegularExpressionValidator>

The regex I included seems to work.
Posted by Abe Miessler1 on 9/8/2010 at 11:17 AM
My first work around will only work if you don't use client side validation. The work around below will work for both client and server side validation.

                            <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
                                        ControlToValidate="InKindTextBox" 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"
                                        ValidationExpression="^\s*\$?\s*(?!\d{4,},)(\d|\d{1,3},(?=\d{3})(?!\d{4}))*(\.\d{1,2})?\s*$" >
                         </asp:RegularExpressionValidator>