Search code examples
javascriptasp.netphone-number

Javascript textbox onkeyup event


Html:

<asp:TextBox ID="phone" " runat="server" AutoCompleteType="Disabled" onkeyup="this.value=this.value.EditPhone()"></asp:TextBox>

Javascript:

 String.prototype.EditPhone= function () {

 var str = document.getElementById('phone').value;
        if (str.substring(0, 1) == "0") // If first value is "0" remove it
            str = str.substring(1, str.length);

        return str;
    };

I remove if first string value is "0".

After that I enter phone number 5552221133 etc..

If i change 11 to 44 i can not remove/change 11 and write new value(44) because of onkeyup value.

If i return null it is not working again. How can i remove/change text according to my code ?


Solution

  • I have

    <asp:TextBox ID="phone" " runat="server" AutoCompleteType="Disabled" onkeyup="this.value=this.value.EditPhone()"></asp:TextBox>