Tuesday, 17 July 2018

Regex accept numeric only. First character can't be 0



 function NumberMask(obj) {
            obj.value = obj.value.replace(/[^0-9]/g, '');
            var txtvalue = document.getElementById("<%=txtUserName.ClientID %>").value;
            var count = txtvalue.length;
            if (count >= 1 && txtvalue == 0) {
                obj.value = obj.value.replace(/[^1-9]/g, '');
            }
        }

<asp:TextBox ID="txtUserName" runat="server" onkeyup="javascript:return NumberMask(this)" onkeydown="javascript:return NumberMask(this)" />

No comments:

Post a Comment