Js detects that the input is all space

  • 2020-03-30 02:49:24
  • OfStack

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

   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;
  <input type="text" id="test"/>
  <input type="button" value=" test " onclick="test()">

Related articles: