Showing posts with label Regular expression. Show all posts
Showing posts with label Regular expression. Show all posts

Thursday, August 29, 2013

Allow only decimal and float values in asp.net using asp RegularExpressionValidator control | Regular expression to validate float and decimal values example

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;
        }

if page has any error then it will return.