Regular Expression always returns true
javascript, jquery, regex
Solution
`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)
Problem
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.