0

I use this code for now :

for (var i = 0; i < all_local_cell.length; i++) {
var td = all_local_cell[I];  //number of textfield cells

td.onpaste = function (e) {
var target = e.srcElement;
var Max_Length = 8;
var length = this.value.length;
if (length > Max_Length) {
// ???
};

I try to check when user paste a text, if this text is > max length keep the <= length and put the extra text on next lines...

e.g. user try to paste online 0 : "indent code by 4 spaces"

0.indent c
1.ode by 4
2. spaces
511
  • 5
  • 6

1 Answers1

0

This function I was using in jQuery Terminal:

function str_parts(str, length) {
    var result = [];
    var len = str.length;
    if (len < length) {
        return [str];
    } else if (length < 0) {
        throw new Error('str_parts: length can\'t be negative');
    }
    for (var i = 0; i < len; i += length) {
        result.push(str.substring(i, i + length));
    }
    return result;
}

it will create array of strings.

For question about intercepting paste event check Intercept paste event in Javascript

jcubic
  • 61,973
  • 54
  • 229
  • 402