由于一个console.log()放在一个使用电话号码Regex验证字符串的函数中,我感到很头疼。
代码:
var phoneIsValid = function(phone){
var re = /^55[1-9][0-9][1-9][0-9]{7}|55[1-9][0-9]9[0-9]{8}$/g;
//console.log(re.test(phone))
return re.test(phone);
};
phoneIsValid('555199997330'); //valid phone, should return true
此功能没问题,可以正确验证字符串。但是如果取消注释console.log行,它将反转函数的返回值。
有谁知道为什么会这样?