Only number or validate text box which receive only number in javascript function
<script type="text/javascript">
function isNumber(evt) {
evt = (evt) ? evt : window.event;
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
}
return true;
}
</script>
For html input Control
-------------------------
<input type="text" id="txtEidNo" onkeypress="isNumber(event)" />
For ASPX TextBox Control
-------------------------
<asp:TextBox ID="txtEidNo" runat="server" onkeypress="return isNumber(event)"></asp:TextBox>
In jquery
----------------
For html input Control
------------------------------
<input type="text" id="txtEidNo" />
<script type="text/javascript">
$(document).ready(function () {
$("#txtEidNo").keydown(function (e) {
if (e.shiftKey)
e.preventDefault();
else {
var nKeyCode = e.keyCode;
//Ignore Backspace and Tab keys
if (nKeyCode == 8 || nKeyCode == 9)
return;
if (nKeyCode < 95) {
if (nKeyCode < 48 || nKeyCode > 57)
e.preventDefault();
}
else {
if (nKeyCode < 96 || nKeyCode > 105)
e.preventDefault();
}
}
});
});
</script>
For ASPX TextBox Control
-------------------------
<asp:TextBox ID="txtEidNo" runat="server" ></asp:TextBox>
<script type="text/javascript">
$(document).ready(function () {
$("#<%= txtEidNo.ClientID%>").keydown(function (e) {
if (e.shiftKey)
e.preventDefault();
else {
var nKeyCode = e.keyCode;
//Ignore Backspace and Tab keys
if (nKeyCode == 8 || nKeyCode == 9)
return;
if (nKeyCode < 95) {
if (nKeyCode < 48 || nKeyCode > 57)
e.preventDefault();
}
else {
if (nKeyCode < 96 || nKeyCode > 105)
e.preventDefault();
}
}
});
});
</script>
<script type="text/javascript">
function isNumber(evt) {
evt = (evt) ? evt : window.event;
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
}
return true;
}
</script>
For html input Control
-------------------------
<input type="text" id="txtEidNo" onkeypress="isNumber(event)" />
For ASPX TextBox Control
-------------------------
<asp:TextBox ID="txtEidNo" runat="server" onkeypress="return isNumber(event)"></asp:TextBox>
In jquery
----------------
For html input Control
------------------------------
<input type="text" id="txtEidNo" />
<script type="text/javascript">
$(document).ready(function () {
$("#txtEidNo").keydown(function (e) {
if (e.shiftKey)
e.preventDefault();
else {
var nKeyCode = e.keyCode;
//Ignore Backspace and Tab keys
if (nKeyCode == 8 || nKeyCode == 9)
return;
if (nKeyCode < 95) {
if (nKeyCode < 48 || nKeyCode > 57)
e.preventDefault();
}
else {
if (nKeyCode < 96 || nKeyCode > 105)
e.preventDefault();
}
}
});
});
</script>
For ASPX TextBox Control
-------------------------
<asp:TextBox ID="txtEidNo" runat="server" ></asp:TextBox>
<script type="text/javascript">
$(document).ready(function () {
$("#<%= txtEidNo.ClientID%>").keydown(function (e) {
if (e.shiftKey)
e.preventDefault();
else {
var nKeyCode = e.keyCode;
//Ignore Backspace and Tab keys
if (nKeyCode == 8 || nKeyCode == 9)
return;
if (nKeyCode < 95) {
if (nKeyCode < 48 || nKeyCode > 57)
e.preventDefault();
}
else {
if (nKeyCode < 96 || nKeyCode > 105)
e.preventDefault();
}
}
});
});
</script>
No comments:
Post a Comment