Javascript regex - no white space at beginning + allow space in the middle

后端 未结 8 1718
故里飘歌
故里飘歌 2020-12-16 15:15

I would like to have a regex which matches the string with NO whitespace(s) at the beginning. But the string containing whitespace(s) in the middle CAN match. So far i have

8条回答
  •  悲&欢浪女
    2020-12-16 15:56

    In your 2nd character class, \\s will match \ and s, and not \s. Thus it doesn't matches a whitespace. You should use just \s there. Also, move the hyphen towards the end, else it will create unintentional range in character class:

    ^[^-\s][a-zA-Z0-9_\s-]+$
    

提交回复
热议问题