Showing posts with label float. Show all posts
Showing posts with label float. Show all posts

Friday, September 27, 2013

textbox float value validation | Using Jquery in asp.net to validate and allow only float,integer,decimal values in the textbox


hi in this post i will show how to validate and allow only float,integer,decimal values in asp.net textbox.

Example:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script language="javascript" type="text/javascript" >
 $(document).ready(function () {
     $("#<%= TextBox1.ClientID %>").keypress(function (event) {

                if (event.which < 46 || event.which > 59) {
                    event.preventDefault();
                } // prevent if not number/dot

                if (event.which == 46 && $(this).val().indexOf('.') != -1) {
                    event.preventDefault();
                } // prevent if already dot
                
            });
        });

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </form>
</body>
</html>

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.