积极答复者
CompareValidator控件验证Currency类型时小数位数怎么指定?

问题
-
<asp:CompareValidator ID="CompareValidator1" runat="server"
ErrorMessage="CompareValidator" ControlToValidate="xxxx" ValueToCompare="0.000" Type="Currency" Operator="GreaterThan"></asp:CompareValidator>
如上,我想让xxxx框里输入的是大于0且允许的小数位数是三位的,可运行的时候报错(0.000无法转换为Currency类型).
跟踪发现CompareValidator调用NumberFormatInfo.CurrentInfo设置小数位数(digits),我系统设置里是2位,请问怎么自定义CompareValidator 的小数位数阿?急
答案
-
你好,你可以用RegularExpressionValidator控件试试。
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body >
<form id="form1" runat="server">
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><asp:RegularExpressionValidator
ID="RegularExpressionValidator1" runat="server"
ErrorMessage="RegularExpressionValidator" ControlToValidate="TextBox2"
ValidationExpression="\d{1,}\.?\d{0,3}"></asp:RegularExpressionValidator>
</form>
</body>
</html>
全部回复
-
你好,你可以用RegularExpressionValidator控件试试。
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body >
<form id="form1" runat="server">
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><asp:RegularExpressionValidator
ID="RegularExpressionValidator1" runat="server"
ErrorMessage="RegularExpressionValidator" ControlToValidate="TextBox2"
ValidationExpression="\d{1,}\.?\d{0,3}"></asp:RegularExpressionValidator>
</form>
</body>
</html>