Friday, 5 December 2014

Text only onkeypress


<asp:TextBox runat="server" ID="txt" class="form-control" onkeypress="return textonly(event,this);"></asp:TextBox>

   //Enter text only
        function textonly(e, obj) {
       
            var code;
            if (!e) var e = window.event;
            if (e.keyCode) code = e.keyCode;
            else if (e.which) code = e.which;
            var character = String.fromCharCode(code);
            var AllowRegex = /^[\ba-zA-Z\s-]$/;
            if (AllowRegex.test(character)) {

                return true;
            }
            return false;
        }

No comments:

Post a Comment