replace unicode in javascript using foreach and charCodeAt

0

I need to check if a unicode is stuck and remove it from the string ...

    //Trae el array.
    $scope.pasteTitle = function (e){
      var stringUnicode = e.originalEvent.clipboardData.getData('text/plain');
      console.log(stringUnicode);
    }

    $scope.pasteTitle = function (e){
        var clipboardData, pastedData;
        // Stop data actually being pasted into div
        e.stopPropagation();
        e.preventDefault();

        // Get pasted data via clipboard API
        pastedData = e.originalEvent.clipboardData.getData('text/plain');
        // Do whatever with pasteddata
        $scope.sanitizeUnicode(pastedData);
    }
    var pastedData =[1];
    function PastedArray(element) {
      var n = pastedData.charCodeAt(e);
      if(n <255){
       replace('');//replace unicode character.
        console.log("UNICODE DETECTADO");
      }else{
        console.log("todo en orden");

        };
    }

    pastedData.forEach(PastedArray);
    
asked by marcos 07.12.2016 в 16:08
source

1 answer

0

You can use a regex to remove unicode characters like this:

"mi string".replace(/[\ud800-\udfff]/g, "");

I usually use this in IE11 to get rid of odd characters that appear when the user pastes text from the clipboard:

"pasted string".replace(/[^ -~]/g,'');
    
answered by 08.12.2016 в 00:12