Detect if string contains any spaces

后端 未结 5 714
醉酒成梦
醉酒成梦 2020-12-23 11:24

How do I detect if a string has any whitespace characters?

The below only detects actual space characters. I need to check for any kind of whitespace.



        
5条回答
  •  长情又很酷
    2020-12-23 12:23

    function hasSpaces(str) {
      if (str.indexOf(' ') !== -1) {
        return true
      } else {
        return false
      }
    }
    

提交回复
热议问题