Regex for allowing alphanumeric,-,_ and space

后端 未结 7 2258
北荒
北荒 2020-12-04 16:43

I am searching for a regular expression for allowing alphanumeric characters, -, _ or spaces in JavaScript/jQuery. I tried Googling but wasn\'t able to find that.

Ca

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-04 17:22

    /^[-\w\s]+$/
    

    \w matches letters, digits, and underscores

    \s matches spaces, tabs, and line breaks

    - matches the hyphen (if you have hyphen in your character set example [a-z], be sure to place the hyphen at the beginning like so [-a-z])

提交回复
热议问题