Reputation: 11
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.
Upvotes: 0
Views: 355
Reputation: 936
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.
Upvotes: 0
Reputation: 357
<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);
}
}
Upvotes: 1