java script function for numbers.
Please send me a java script function which accept only numbers on keypress event.
Virtual. Every session is recorded and published here on CSharp TV.
Answer a question in the forums and earn +2 points for every reply.
Ask a questionKnow the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Niradhip ChakrabortyPosted Jun 3, 2008, 3:42 AM
function
numbersonly(e, decimal) {var
key;var
keychar;if
(window.event) {key = window.
event.keyCode;}
else
if (e) {key = e.which;
}
else
{ return true;}
keychar = String.fromCharCode(key);
if
((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ) { return true;}
else
if ((("0123456789").indexOf(keychar) > -1)) { return true;}
else
if (decimal && (keychar == ".")) { return true;}
else
return false;}
Niradhip ChakrabortyPosted Jun 3, 2008, 5:33 AM
Try it:
txtCardNumber.Attributes.Add(
"OnKeyPress", "return numbersonly(event, false)");Milton SmithPosted Jun 3, 2008, 5:23 AM
txtCardNumber.