强制 ASP.NET 文本框显示带有 $ 符号的货币 [英] Force ASP.NET textbox to display currency with $ sign

查看:16
本文介绍了强制 ASP.NET 文本框显示带有 $ 符号的货币的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让 ASP.NET 文本框只接受货币值,并且在验证控件时,预先插入 $ 符号?

Is there a way to get an ASP.NET textbox to accept only currency values, and when the control is validated, insert a $ sign beforehand?

例子:

10.23 变为 10.23 美元
1.45 美元保持 1.45 美元
10.a由于不是有效数字而引发错误

10.23 becomes $10.23
$1.45 stays $1.45
10.a raises error due to not being a valid number

我有一个用于验证数字是否有效的 RegularExpressionValidator,但我不知道如何将 $ 符号强制输入文本.我怀疑 JavaScript 可能会工作,但想知道是否有其他方法可以做到这一点.

I have a RegularExpressionValidator that is verifying the number is valid, but I don't know how to force the $ sign into the text. I suspect JavaScript might work, but was wondering if there was another way to do this.

推荐答案

ASP.NET MaskedEditAJAX Control Toolkit 中的 控件可以完成您的要求.

The ASP.NET MaskedEdit control from the AJAX Control Toolkit can accomplish what you're asking for.

这篇关于强制 ASP.NET 文本框显示带有 $ 符号的货币的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆