I am implementing a chat-function to a JavaScript game using WebSocket. I want to replace non-ascii characters the user has written in the input textfield with other letters. Ä is replaced with a and Ö is replaced with o. And every other non-ascii characters should be replaced by "".
var message = document.getElementById("write_message").value;
message = message.replace(/ä/g, "a").replace(/ö/g, "o");
message = message.replace(/^[\000-\177]/g, "");
ws.send("M" + message);
I tried even simpler versions of the above code, but somehow all user input seemed to be replaced. Even ascii-characters. I found the regular expression from another Stackoverflow question.
encodeURIComponent?