为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

温温酱 2018-10-08 13:39:37
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));         }       })谢谢!
查看完整描述

1 回答

?
宝慕林4294392

TA贡献2021条经验 获得超8个赞

/s*/g能匹配成功任意字符,(包括空串。个数随意,没有也行).因为所有的都能包含""。

评论区转码了,写这了

多个空格啊?>=2个?/\s\s+/g; ^&写不写你看着来,没太明白你的意思。


查看完整回答
反对 回复 2018-11-01
  • 1 回答
  • 0 关注
  • 528 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号