Advertisement
Koragg

Remove Control Characters (NPC) [HTML/JavaScript]

Feb 25th, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!-- ASCII Device Control Characters: https://www.w3docs.com/learn-html/html-ascii.html -->
  2. <!-- Remove Device Control Characters:
  3. https://stackoverflow.com/questions/26741455/how-to-remove-control-characters-from-string
  4. https://stackoverflow.com/questions/21284228/removing-control-characters-from-a-utf-8-string-in-php
  5. -->
  6.  
  7. <div id='broken'>&#01;test</div>
  8. <div id='fixed'></div>
  9.  
  10. <script>
  11.     var textareaValue = document.getElementById('broken').innerHTML;
  12.     var fixedText = textareaValue.replace(/[\x00-\x1F\x7F-\x9F]/u, "");
  13.     document.getElementById('fixed').innerHTML = fixedText;
  14.     alert(textareaValue + ' : ' + textareaValue.length);
  15.     alert(fixedText + ' : ' + fixedText.length);
  16. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement