Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to limit characters in number input js

function limit(element)
{
    var max_chars = 2;

    if(element.value.length > max_chars) {
        element.value = element.value.substr(0, max_chars);
    }
}


<!-- HTML -->
<input type="number" onkeydown="limit(this);" onkeyup="limit(this);">
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #limit #characters #number #input #js
ADD COMMENT
Topic
Name
9+9 =