JavaScript determines whether the string is empty characters and whether all are spaces

1. Determine whether the string is an empty character, that is, the user has entered a space

  var strings = ' ';
  if (strings.replace(/(^s*)|(s*$)/g, "").length ==0){
     alert('不能为空');
  }

2、判断字符串是否都是空格

    function isNull ( str ) {
      var regu = "^[ ]+$";
      var re = new RegExp(regu);
      return re.test(str);
   }

Reference article: https://www.jb51.net/article/86543.htm

Guess you like

Origin blog.csdn.net/weixin_40538702/article/details/109069971