Spot the bug in the global email validator

from Regular expressions
Node 24 intermediate 5 min 1 issue to find

Why does the second valid address print false?

JavaScript
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/g;

function validEmail(input) {
  return emailPattern.test(input);
}

console.log(validEmail("[email protected]"));
console.log(validEmail("[email protected]"));
Open in playground
Report an error