Hi in this post i will show how to allow only decimal and float values in asp.net using regular expression.
In Aspx:
<asp:TextBox ID="txtEmpSalary" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="ValidateTotalBillAmount" ErrorMessage="Enter Proper value" ControlToValidate="txtEmpSalary" ValidationExpression="(?<=^|)\d+(\.\d+)?(?=$|)|(?<=^| )\.\d+(?=$|)" runat="server">
</asp:RegularExpressionValidator>
In code-behind:
if (Page.IsValid = = false)
{
return;
}
In Aspx:
<asp:TextBox ID="txtEmpSalary" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="ValidateTotalBillAmount" ErrorMessage="Enter Proper value" ControlToValidate="txtEmpSalary" ValidationExpression="(?<=^|)\d+(\.\d+)?(?=$|)|(?<=^| )\.\d+(?=$|)" runat="server">
</asp:RegularExpressionValidator>
In code-behind:
if (Page.IsValid = = false)
{
return;
}
if page has any error then it will return.
No comments:
Post a Comment