function onKeyPressBlockNumbers(e)This one is the oppsite purpose:
{
//e.keyCode is for IE; e.which is for Firefox
var key = window.event ? e.keyCode : e.which;
var keychar = String.fromCharCode(key);
reg = /\d/;
return !reg.test(keychar);
}
function onKeyPressOnlyNumbers(e)Here is how to use:
{
var key = window.event ? e.keyCode : e.which;
var keychar = String.fromCharCode(key);
reg = /\d/;
return reg.test(keychar);
}
<asp:TextBox ID="TextBox1" onkeypress="return onKeyPressBlockNumbers(event);" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" onkeypress="return onKeyPressOnlyNumbers(event);" runat="server"></asp:TextBox>
Note: This cannot prevent users from pasting numbers onto the TextBox.
No comments:
Post a Comment