验证货币输入的最佳方式? [英] Best way to validate currency input?
问题描述
我已经创建了下面,我想将允许以下列形式输入文本框和CompareValidator:
- 5
- 5.00
- $ 5.00
不幸的是它不允许在它的美元符号的版本。什么是做一个类型对证的货币,如果你不允许美元符号的意义呢?有没有办法让这个符号?
< ASP:文本框ID =tb_CostShare=服务器文本='<%#的eval(CostShare,{0:$ 0.00})%&GT ;'的CausesValidation =真/>
< ASP:CompareValidator ID =vld_CostShare
=服务器
的ControlToValidate =tb_CostShare
操作=DataTypeCheck
TYPE =货币
的ValidationGroup =VLD
的ErrorMessage =你必须输入金额为成本分担。 />
该CompareValidator并不支持货币符号。您可以preFIX您的输入控制与$或使用常规的前pression验证,这页面有一个例子。
下面的模式将匹配你的例子( http://www.regexlib.com 提供):
^ \\ $([0-9] {1,3},([0-9] {3},)* [0-9] {3} |?[ 0-9] +)。(。[0-9] [0-9])?$
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'." />
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):
^\$?([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)(.[0-9][0-9])?$
这篇关于验证货币输入的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!