I want to create a function that removes all unwanted characters from a text. That´s waht I came up with, but it doesn´t work:
var invalid = "^°\"§%()[]{}=\\?´`'#<>|,;.:-+_";
for (var n = 0; n < invalid.length; n++)
{
var r = new RegExp(invalid[n],"g");
toCheck.replace(r,"");
}
You don't need to loop through invalid characters. Just use regex like this:
var invalid = /[°"§%()\[\]{}=\\?´`'#<>|,;.:+_-]+/g;
var repl = toCheck.replace(invalid, "");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With