Strip any character that is above 127 in the ASCII table?

I am trying to remove strange characters. Those strange characters are apparently very difficult to remove. In this jsfiddlee I included a lot of examples from stackoverflow answers like this, but I cannot get it to work.

$("textarea").text().replace(/[^A-Za-z 0-9 \.,\?""!@#\$%\^&\*\(\)-_=\+;:<>\/\\\|\}\{\[\]`~]*/g, '');
$("textarea").text().replace(/[\uE000-\uF8FF]/g, '');
$("textarea").text().replace(/[^\x00-\x7F]/g, "");
    return char.charCodeAt(0)<=255 ? char : '<b>' + char + '</b>';

I just realised I forgot to add the replaced text into the text(), so the textarea does not get replaced.

The textarea contains weird characters, and those are the ones I want to strip. What am I doing wrong?


Expanding on the third option in the list:

$("textarea").text(function(_, value) {
    return value.replace(/[^\x00-\xFF]/g, '');

Seems to work as intended, but is rather open to control characters in the ASCII range. The best is to strip out letters that aren't in the printable range.

$('textarea').text(function(_, value) {
    return value.replace(/[^ -~]/g, '');


Need Your Help

Drupal 7 Ajax Forms

ajax forms drupal rendering drupal-7

I am using Drupal 7, and I am building a web site, that has a contact form in the footer which should appear in every page. The requirements was to make this form work via Ajax, all examples I foun...

how to access values in multiple select control in php

php ajax multiple-select

I am using multiple select control for a requirement.It goes like this:the first dropdown list shows all the columns of the table in the database it is done.What ever the values user selects in the...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.