I’m working with a web page containing a form with a textarea element. I want to restrict the input values to only numbers, using JavaScript. One method I have found is to check the keyvalues when users are entering data:
function checkForEnter() {
if (!((event.keyCode >= 48) || (event.keyCode <= 57))) {
//event.stopPropagation(); throw error with IE ver 8
event.cancelBubble = true;
event.returnValue = false;
return false;
}
}
What other method could I use to restrict the values entered?
Thanks for your help
this solution works for me
The inputext has attach two events to the same function(checkForEnter ) , onkeypress and onkeydown
both cases I validate ONLY numbers
no more bla , bla bla,
ps. I cannot
I can not make multiple comparisons in javascript
: (
for that reason use if .. if .. if