How can I determine if a string only contains spaces, using javascript?

前端 未结 5 1266
滥情空心
滥情空心 2021-02-05 23:24

How can I determine if an input string only contains spaces, using javascript?

5条回答
  •  情深已故
    2021-02-05 23:59

    Alternatively, you can do a test() which returns a boolean instead of an array

    //assuming input is the string to test
    if(/^\s*$/.test(input)){
        //has spaces
    }
    

提交回复
热议问题