Gives solution for any Error occurs in any Programming Language, .Net Core 3.1, 3.0, C#,Asp.Net,Sqlserver,MVC,Java,Php,Html,Css,Jquery,errors and solutions,Latest News,Technology

Monday 14 March 2016

Enter Only Integers in Asp.Net Textbox using Javascript and Jquery

No comments :
Here I will explain about if you want to enter only digits/integers in textbox you need to write in following code in javascript and jquery with client side validation.Here I am using bootbox.js alert.

//Function to allow only  numeric to textbox
        var specialKeys = new Array();
        specialKeys.push(8); //Backspace
        function IsNumeric(e) {
            debugger;
            var keyCode = e.which ? e.which : e.keyCode
            var ret = ((keyCode >= 48 && keyCode <= 57) || specialKeys.indexOf(keyCode) != -1);
            if (!ret)
            {
                bootbox.alert('Input Digits : (0-9)');
            }
            //$('.error').css(ret ? $('.error').css('display', 'none') : $('.error').css('display', 'inline'));
            return ret;
        }
<asp:Button ID="btnSave" runat="server" BackColor="black" Height="25px" Width="70px" Text="Save" OnClientClick="IsNumeric(event)" OnClick="btnSave_Click" Visible="false" />

No comments :

Post a Comment