function makeSafe(thisText, allowSpace){
var w = "!@#$%^&*()+=[]\\\';,./{}|\":<>?";
var s = 'abcdefghijklmnopqrstuvwxyz0123456789-';
var x = new Array('àáâãäå', 'çč', 'èéêëě','š','ř','ž','á', 'ìíîï', 'ñ', 'ðóòôõöø', 'ùúûüů', 'ýÿ',' ','.');
var r = new Array('a', 'c', 'e','s','r','z','a', 'i', 'n', 'o', 'u', 'y','-','-');
if(allowSpace){
s = s + ' ';
}
thisText = thisText.toLowerCase();
var newText = new Array();
for (i = 0; i < thisText.length; i++){
thisChar = thisText.charAt(i);
if(w.indexOf(thisChar) == -1){
if(s.match(''+thisChar+'')){
newText[i] = thisChar;
}else{
for (j = 0; j < x.length; j++){
if(x[j].match(thisChar)){
newText[i] = r[j];
}
}
}
}
}
return newText.join('');
}
<input onkeypress="return !isNaN(String.fromCharCode(event.charCode || event.keyCode))">
// stripslashes
String.prototype.stripslashes = function(){
return this.replace(/<.*?>/g, '');
};
String.prototype.htmlspecialchars = function(){
var str = this.replace(/&/g, '&');
str = str.replace(/</g, '<');
str = str.replace(/>/g, '>');
str = str.replace(/"/g, '"');
return str;
};
// htmlspecialchars
var str = '<b>my personal website:</b> ';
str += '<a href="http://www.jonasjohn.de/">jonasjohn.de</a>';
document.write("Original string (html): '" + str + "'<br/><br/>");
var str_no_html = str.stripslashes();
document.write("- String without HTML tags: '" + str_no_html + "'<br/>");
var str_hsc = str.htmlspecialchars();
document.write("- String with converted HTML tags: '" + str_hsc + "'");