请问我这段代码,无论如何打印的正则都是true?是正则写错了,还是因为test()是js的方法?

var reg = /\s*/g;
      $('.modal-content').find('input').focusout(function () {        if ($(this).val() == '' || reg.test($(this).value)) {
          $(this).css('backgroundColor','#FFEFEF');
          $(this).nextAll('.hintWrap').css('display','block');          console.log(reg.test($(this).value));
        } else {
          $(this).css('backgroundColor','#F5F5F5');
          $(this).nextAll('.hintWrap').css('display','none');          console.log(reg.test($(this).value));
        }
      })

谢谢!


温温酱
浏览 529回答 1
1回答

宝慕林4294392

/s*/g能匹配成功任意字符,(包括空串。个数随意,没有也行).因为所有的都能包含""。评论区转码了,写这了多个空格啊?>=2个?/\s\s+/g; ^&写不写你看着来,没太明白你的意思。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript