我正在使用 CompareValidator 来检查我的一个表单上的用户输入,但由于某种原因它不允许我输入美元符号。
According to MSDN比较验证器中的货币数据类型允许:
A decimal data type that can contain currency symbols.
我正在使用下面的控件来验证:
<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" />
为了确定起见,我还在 web.config 中添加了以下内容:
<globalization culture="en-US" uiCulture="en-US"/>
但它仍然说任何带有 $ 的输入都是无效的。我在这里遗漏了什么吗?
最佳答案
该线程中的最后一条评论说明了原因并为您提供了一些想法:
专门讨论此问题的文章:
ASP.Net: Validating a TextBox with a Dollar Sign (建议使用正则表达式验证器)。
关于asp.net - 为什么我无法验证其中包含 $ 符号的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3663190/