Adding a DOT (.) to Regular Expression

前端 未结 1 495
醉酒成梦
醉酒成梦 2021-01-27 00:24

I\'m looking to add a (.) to the allowed characters in my function below:

$(id).bind(\'keypress\', function(event) {
    var regex = new RegExp(\"[(         


        
相关标签:
1条回答
  • 2021-01-27 00:46

    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.

    0 讨论(0)
提交回复
热议问题