Q:

regex only allow few special character and space in string? 

I am trying to write one regex where I need to follow all conditions. 

characters and numbers are allowed (a-z A-Z 0-9)
Space allowed
,-/_() these only special character allowed. 

I have tried like this
var str = "The";
  var patt = new RegExp(/^[\w-_.]*$/);
  var res = patt.test(str);

it passes in some scenarios but fails in some scenarios 

A:

You can use this
^[\w.)(,/ -]+$

^ - Start of string
[\w.)(,/ -]+ - Matches alphabets, digits, ( , ) , / , space , - and ,
$ - End of line 

let test = (str) => /^[\w.)(,/ -]+$/.test(str)

console.log(test("The vbbv"))
console.log(test("The )( "))
console.log(test("The @"))

side note:- When using - in character class it should be at end of class if you meant to use it as - not as range, it's not case here but it's good to follow this rule

