0

I am using a text box. It should restrict all other keys except 1-99 while entering into the textbox. i need code to restrict them.

  • On SO it's appreciated when you make an effort at solving your issue. What have you tried? Please show the current code you're using and what specifically it isn't doing. – DACrosby Aug 26 '15 at 04:35

2 Answers2

1
<input type="number" onkeydown="limit(this);" onkeyup="limit(this);">

LIMIT With JS

function limit(element)
{
var max_chars = 2;

   if(element.value.length > max_chars) {
       element.value = element.value.substr(0, max_chars);
   } 
}
Ghulam Ali
  • 357
  • 4
  • 17
0

The answers provided for this SO question should help you figure it out. It's a combination of HTML and JavaScript. There are two main ideas: 1 - use input with type=number as Ghulam Ali suggested to restrict inputs to your range of values and augment that with some JS to restrict the length. 2 - use input with type=text to restrict the length and augment it with some JS to restrict inputs to your range of values.

Community
  • 1
  • 1
Dan Iveson
  • 926
  • 6
  • 10