1var str = 'Some very long string';
2if(str.length > 10) str = str.substring(0,10);
3
1function limit(element)
2{
3 var max_chars = 2;
4
5 if(element.value.length > max_chars) {
6 element.value = element.value.substr(0, max_chars);
7 }
8}
9
10
11<!-- HTML -->
12<input type="number" onkeydown="limit(this);" onkeyup="limit(this);">
1function limit(element)
2{
3 var max_chars = 2;
4
5 if(element.value.length > max_chars) {
6 element.value = element.value.substr(0, max_chars);
7 }
8}