How it is better to check (test) if text contains only characters from set (for example if text contains only punctuation marks)
var regex = /[\.,-\/#!$%\^&\*;:{}=\-_`~()]/g
res = text.replace(regex, '')
if (res) return false
so I made it with replace is it possible to do it with regex.test?
Yes it is. There are two possibilities. One is, that you use anchors to assert that the full string is made up of these:
Alternatively you can use a negated character class and see whether it matches and then again negate the result
Note that
,-\/is a range that includes,-./. This is redundant and may become a source of errors if the character class is ever changed. You might want to simplify your character class to:(Or the negated version of that, depending on which approach you choose.)