для одной строки в хроме
<div contenteditable="true">write here</div>
<script>
document.querySelector("div").addEventListener("input", function () {
var sel = window.getSelection(),
range = sel.getRangeAt(0),
pos = range.endOffset;
this.innerHTML = this.innerHTML.substr(0, 10);
try {
range.setStart(range.startContainer , pos);
} catch (e) {
range.setStart(range.startContainer , pos - 1);
}
sel.removeAllRanges()
sel.addRange(range);
});
</script>