limit text to certain number javascript code example
Example 1: 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);">
Example 2: Limit text to specified number of words using Javascript
"Want better search results? See our search tips".split(" ").splice(0,3).join(" ")