Regex - match a string without having spaces

前端 未结 2 1163
孤独总比滥情好
孤独总比滥情好 2020-12-11 20:08

Building an regular expression that will reject an input string which contain spaces.

I have a following expression, but its not working as well;

^[         


        
2条回答
  •  时光说笑
    2020-12-11 20:28

    I suppose that you'll be using .test method on regex, /\s/g this one should do the job, it will return true if there's any space in the string. ex: /\s/g.test("String123/test") this will return false which means that the string is valid /\s/g.test("String123 /test) this will return true which means that the string is not valid

提交回复
热议问题