Monday, 14 March 2016
Enter Only Integers in Asp.Net Textbox using Javascript and Jquery
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" />
//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" />
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment