Wednesday, 21 January 2015

Dot and zero as first character in textbox using javascript ?

  < script type="text/javascript" language="javascript" >

        String.prototype.startsWith = function (str)
        {
            return (this.indexOf(str) === 0);
        }

        function ValidationofPaymentAmount{
            var txtNo = document.getElementById("txtNumber").value;
            if (txtNo .startsWith(".") || txtNo.startsWith("0")) // true
            {
                document.getElementById("txtNumber").value = "";
                alert("you can not insert dot and zero as first character");
            }
        }
    < /script>


In code Behind: 

<asp:TextBox ID="txtNumber" runat="server" onkeyup="ValidationofPaymentAmount();"></asp:TextBox> 

No comments:

Post a Comment