Replace dodgy chars

Hi.
I’ve got this php code


protected function sanatizeInputValue($value)
  {
    $dodgychars = "#[|\\!\\"'\\$&#163;&#37;&\\/()=?^<>\\*\\+\\-]#";
    $filterValue = preg_replace($dodgychars,"-",$value); 
    return substr($filterValue,0,255);
  }

How can I tanslate this in js code :slight_smile:
I tried but with very poor result :frowning:
can you show me the way, please ?

Bye


var toReplace = {
    '|': '-',
    '!': '-',
    '"': '-',
    '&#163;': '-',
    '&#37;': '-',
    '&': '-',
    '/': '-',
    '(': '-',
    ')': '-',
    '=': '-',
    '?': '-',
    '^': '-',
    '*': '-',
    '&#176;': '-',
    '*': '-',
    '&#167;': '-',
    '@': '-',
    '#': '-',
    '_': '-',
    ';': '-',
    ':': '-',
    '!': '-',
    '.': '-',
    '<': '-',
    '<': '-',
};
var string = '<This ?^*&#249; is a test'.replace(/./g, function (match) {
    return toReplace[match] || match;
});
alert(string); 

:slight_smile:

I’m lucky I found it in my repository
I don’t remember the really author :slight_smile:


function sanatizeInputValue(value) {
    var dodgyChars = /[|!"'$&#163;&#37;&\\/()=?^<>*+-]/g;
    return value.replace(dodgyChars, '-').substring(0, 255);
}

Thanks for the help
It was my first attempt but
it didn’t work may be for the lack
of the modifier :frowning:

Bye