I\'m looking to add a (.
) to the allowed characters in my function below:
$(id).bind(\'keypress\', function(event) {
var regex = new RegExp(\"[(
Note that -
should either be at the beginning or at the end of character class or has to be escaped by a backslash \
, since it indicates range as in a-z
/[()a-zA-Z0-9 ?,/.-]/
Also, if dynamic regex is required, just use the regex literal as in above, if not you'd have to remove the delimiters / /
and use the actual regex [()a-zA-Z0-9 ?,/.-]
as a String
which can be used in RegExp
constructor.