0

I just had a big headache because of a console.log() placed inside a function that validates a String using a Phone number Regex.

Code:

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

This function is allright, properly validates the string. But if you uncomment the console.log line, it inverts the return value of the function.

Do anyone knows why this happens?

Pedro Leão
  • 9
  • 1
  • 1

0 Answers0