Regex for validating a string with pre-specified special characters

后端 未结 3 1507
梦如初夏
梦如初夏 2020-12-21 09:16

I am looking for a regex to validate a string. I want to allow numbers, alpha characters, spaces and any of the following characters in any order:

+ - ( ) ,
         


        
相关标签:
3条回答
  • 2020-12-21 09:30
    /^[a-zA-Z0-9+(), -]+$/
    
    0 讨论(0)
  • 2020-12-21 09:39

    The correct regex was:

    ^[a-zA-Z0-9+\\s(),-]+$
    

    many thanks to Slaks who almost responded with the correct one except not accomodating the whitespaces

    0 讨论(0)
  • 2020-12-21 09:42

    Like this:

    /^[a-zA-Z0-9 +(),-]+$/
    

    EDIT: Now accepts spaces.

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