Java script function for numbers.
Please send me a java script function which accept only numbers on keypress event.
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Niradhip ChakrabortyRank #429 · 5.8K reputationPosted Jun 2, 2008, 11:42 PM EDT
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;}
Milton Smith55 reputationPosted Jun 3, 2008, 1:23 AM EDT
txtCardNumber.
Niradhip ChakrabortyRank #429 · 5.8K reputationPosted Jun 3, 2008, 1:33 AM EDT
Try it:
txtCardNumber.Attributes.Add(
"OnKeyPress", "return numbersonly(event, false)");