Best way to validate currency input?

Posted by Abe Miessler on Stack Overflow See other posts from Stack Overflow or by Abe Miessler
Published on 2010-04-22T19:27:32Z Indexed on 2010/04/22 19:33 UTC
Read the original article Hit count: 161

Filed under:
|
|

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" 
                                    runat="server" 
                                    ControlToValidate="tb_CostShare" 
                                    Operator="DataTypeCheck" 
                                    Type="Currency" 
                                    ValidationGroup="vld" 
                                    ErrorMessage="You must enter a dollar amount for 'Cost Share'." />    

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about validation