Js detects that the input is all space


JavaScript to determine the input content can not be all space method, to avoid the input box of the contents of the input space:

<html>
 <head>
  <script>
   function checkBlankSpace(str){
    while(str.lastIndexOf(" ")>=0){
      str = str.replace(" ","");
    }
    if(str.length == 0){
     alert(" The input cannot be empty ");
    }
   }
   function test(){
    var testStr = document.getElementById("test").value;
    checkBlankSpace(testStr);
   }
  </script>
 </head>
 <body>
  <input type="text" id="test"/>
  <input type="button" value=" test " onclick="test()">
 </body>
</html>