关于ASP.NET中的一些数据验证实现方法.
1.用正则判断一个数字是否是16位长度,4位小数的数字[decimal(16,4)]:
<asp:RegularExpressionValidator ID="uxUpdatePriceValidator" runat="server" ErrorMessage='<%$ Resources:UIElement,msg00045 %>'
ControlToValidate="uxUpdatePriceDataTextBox" ValidationExpression='<%$ Resources:UIElement,regReal16Number4Decimal1%>' Text="*" ValidationGroup="Detail" Display="Dynamic">
</asp:RegularExpressionValidator>
资源文件UIElement中的regReal16Number4Decimal1项目为:^([0-9]{1,12})(/.[0-9]{0,4})?
2.用控件判断一个数字是否是16位长度,4位小数的数字[decimal(16,4)]:<asp:RangeValidator ID="uxUpdatePriceDataTextBoxRangeValidator" runat="server" ControlToValidate="uxUpdatePriceDataTextBox" Display="Dynamic" ValidationGroup="Detail" MaximumValue="1000000000000" MinimumValue="0.0001" Type="Double" Text="*" ErrorMessage='<%$ Resources:UIElement,msg00045%>'></asp:RangeValidator>
3.验证强制要求一个输入框必须输入:
<asp:RequiredFieldValidator ID="uxTextBoxRequired6" runat="server" ErrorMessage='<%$ Resources:UIElement,msg0002%>'
Text="*" Display="Dynamic" ControlToValidate="uxInsertPriceDataTextBox" ValidationGroup="Detail">
</asp:RequiredFieldValidator>
4.对应消息显示控件:
<asp:ValidationSummary id="DetailValidationSummary" runat="server" ValidationGroup="Detail" DisplayMode="SingleParagraph"> </asp:ValidationSummary>