I have the following code (pulled from this question) for setting a character limit on textareas.
function maxLength(el) {
if (!("maxLength" in el)) {
var max = el.attributes.maxLength.value;
el.onkeypress = function () {
if (this.value.length >= max) return false;
};
}
}
var maxtext = document.getElementsByClassName("maxtext");
for (var i = 0; i < maxtext.length; i++) {
maxLength(maxtext[i]);
}
And an example of my html for textareas:
<textarea maxlength="150" class="maxtext"></textarea>
This all works just fine in Firefox and Chrome. In IE7+, it will stop me if I type up to the limit, but I'm then able to copy/paste text without restriction.
Any way to modify this script to prevent copy/pasting beyond the max character limit?