Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
<asp:textbox ID="Telephonetextbox" cssclass="input" runat="server" onkeyup="f_a(this);" Text='<%# Bind("telephone") %>' AutoPostBack="true"/>

XML
<script type="text/javascript">
    $(document).ready(function () {
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(f_a);
        f_a(this);
    });
    function f_a(v_id) {
        return document.getElementById(v_id);
        $(document).ready(f_a(this));
    }
    var obj = document.getElementById("#<%=fmAuthRoles.FindControl("Telephonetextbox").ClientID %>");

    f_a(obj).maxLength = 14;

    f_a(obj).keyup = function (v_e) {
        v_e = v_e || window.event;

        if (v_e.keyCode >= 65 && v_e.keyCode <= 90) {
            this.value = this.value.substr(0, this.value.length - 1);
            return false;
        } else if (v_e.keyCode >= 37 && v_e.keyCode <= 40) {
            return true;
        }

        var v_value = (this.value.replace(/[^\d]/g, ''));
        if (v_value.length == 7) {
            this.value = (v_value.substring(0, 3) + "-" + v_value.substring(3, 7));
        }
        else if (v_value.length == 10) {
            this.value = ("(" + v_value.substring(0, 3) + ") " + v_value.substring(3, 6) + "-" + v_value.substring(6, 10));
        };
    }
</script>
Posted
Comments
Sergey Alexandrovich Kryukov 28-Jul-15 20:15pm    
What's the problem and what do you want to achieve?
—SA
Haya8888 29-Jul-15 11:56am    
Hi, i tried to call the function f_a(this) to format the phone number on asp:textbox onkeyup="f_a(this)", but it did not work. The asp:textbox was placed with UpdatePanel - EditTemplate. What did I do wrong? thanks....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900