Question: I have following regular expression in JQuery. It always returns true.

```
var reg = new RegExp("[a-zA-Z0-9 ,]+");
var key = $('#keyId').val().trim();
if (key.match(reg)) {
  $("#TitleError").hide();
}
else {
  $("#TitleError").text("special characters not allowed!!").show();

}

```

It returns true for everything, for example "ABCD, ^&&&^&" should be false, it returns true.

Answer: 
`match` returns the matches found in the string. what you really want is `test` eg. like this

```
/^[a-zA-Z0-9 ,]+$/.test(key)
or 
reg.test(key)

```
You regexp should be:

`var reg = new RegExp('^[a-zA-Z0-9 ,]+$');`