-1

This shows a warning of Unnecessary escape character. how do I resolve this.

    validateEmail = email => {
        var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        return re.test(String(email).toLowerCase());
    };
chintuyadavsara
  • 1,401
  • 1
  • 9
  • 22
Syed Ahmed
  • 31
  • 4

1 Answers1

0

There is one unnecessary escape, and that's \[ within the character class:

var re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

You do need to escape the ] because it would otherwise end the character class, but an opening bracket is only a metacharacter when it's not inside a character class.

Tim Pietzcker
  • 313,408
  • 56
  • 485
  • 544