Sunday, May 17, 2009

Textbox validation for numeric and other key codes.

function fncInputNumericValuesOnly()
{
if(!(event.keyCode==45||event.keyCode==46||event.keyCode==48||event.keyCode==49||event.keyCode==50||event.keyCode==51||event.keyCode==52||event.keyCode==53||event.keyCode==54||event.keyCode==55||event.keyCode==56||event.keyCode==57))
{
event.returnValue=false;
}
}

< asp:TextBox id="txtQty" runat="server" onkeypress= "fncInputNumericValuesOnly('')"/>

Or add any other ascii code as keyCode to allow like:

8=backspace
190=dot
37=left arrow
39=right arrow
16=shift

No comments:

Post a Comment