Take the 2-minute tour ×

I have created the TextBox and CompareValidator below which I thought would allow input in the following forms:

  • 5
  • 5.00
  • $5.00

Unfortunately it's not allowing the version with the dollar sign in it. What is the point of doing a type check against currency if you don't allow the dollar sign? Is there a way to allow this symbol?

            <asp:TextBox ID="tb_CostShare" runat="server" Text='<%# Eval("CostShare", "{0:$0.00}")%>' CausesValidation="true" />
            <asp:CompareValidator   ID="vld_CostShare" 
                                    ErrorMessage="You must enter a dollar amount for 'Cost Share'." />    
share|improve this question
What if you use {0:c} instead? –  Greg Apr 22 '10 at 19:34
A currency validation could include currencies other than USD... –  Austin Salonen Apr 22 '10 at 19:37
@Austin - I don't want to validate anything other that USD. @Greg - How would I use {0:c} to validate? –  Abe Miessler Apr 22 '10 at 20:21
I don't know, maybe it doesn't work that way. –  Greg Apr 23 '10 at 14:19
Why do you want the dollar sign in the validation? You should just be validating the data 5.35. If you want to display the $ sign, place a label on the front of the text box. That way you can also store it as a decimal in SQL. –  Dustin Laine Apr 27 '10 at 21:03
show 1 more comment

2 Answers

up vote 5 down vote accepted

The CompareValidator doesn't support currency symbols. You can prefix your input control with the $ or use a regular expression validator, this page has an example.

The following pattern will match your examples (courtesy of http://www.regexlib.com):

share|improve this answer
add comment

Also, you could write a custom validator to parse the string, with or without $. But you would need to write some Javascript to get any client side validation.

share|improve this answer
add comment

Your Answer


